Stop 14 · Spring Boot & Backend DevelopmentTopics · 1/13

HTTP & REST Fundamentals

Part of the Java Roadmap

In short

Status codes, idempotency, headers, caching: interviewers use these to check you really understand the web, not just your framework. They're quick wins if you prepare.

HTTP is the request-response protocol behind every web API, with methods like GET, POST, PUT and DELETE, status codes and headers. REST is a style that models data as resources with clear URLs and uses those methods consistently.

The purple blob hands a stamped envelope to a post office clerk who gives back a receipt.

Think of it like this

Sending a parcel at the post office

The envelope has an address (URL), a service type like speed post (method), stamps and labels (headers) and the letter inside (body). The counter hands you a receipt (status code) saying accepted, rejected or wrong address.

Watch it happen

One resource, many conversations

Client
API

POST /orders

1/8Create a new order. POST is not idempotent: sending it twice can create two orders.

The big ideas

What you need to know

Safe and idempotent

GET is safe. GET, PUT and DELETE are idempotent: repeating them gives the same result. POST usually isn't.

Status code families

2xx success, 3xx redirect, 4xx client mistake, 5xx server failure. Know 200, 201, 204, 304, 400, 401, 403, 404, 409, 429, 500 and 503.

Headers do real work

Content-Type, Authorization, Cache-Control, ETag and Location carry meaning. Name a few with their purpose.

REST is stateless

Each request carries everything needed, like the auth token. That's what lets you add servers freely.

See it in code

Walk through the code

http
1POST /api/orders HTTP/1.12Host: api.shop.dev3Content-Type: application/json4Authorization: Bearer eyJhbGciOi...5Idempotency-Key: 8f14e45f-ea7c-4e1b6 7{ "productId": 42, "quantity": 2 }8 9HTTP/1.1 201 Created10Location: /api/orders/98111Content-Type: application/json12 13{ "id": 981, "status": "pending_payment" }

1/4Method, path and protocol version.

An Idempotency-Key lets the server spot a retried POST and return the first result instead of creating a second order.

Save yourself the pain

Common mistakes

Oops

Returning 200 with { "error": "not found" } in the body.

Do this instead

Use the real status code, 404. Clients, caches and monitoring tools all rely on it.

Oops

Mixing up 401 and 403.

Do this instead

401 means not authenticated (who are you?). 403 means authenticated but not allowed.

Your mission

Status code drill

~25 min

Quick check

A request times out and the client retries automatically. Which one is safe to retry without doubling the effect?

Go deeper

  1. 1Call a public API with curl or Postman and read the status code and headers.
  2. 2Design URLs for a task API: list, get one, create, update and delete.
  3. 3Learn what 200, 201, 204, 400, 401, 403, 404 and 500 mean.

Also part of these roadmaps

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge