REST fundamentals: resources, HTTP semantics and status codes
coreintermediateA REST API models a system as nouns, not verbs — resources like /orders or /orders/42, not endpoints like /getOrder. The HTTP method carries the verb (GET reads, POST creates, PUT replaces, PATCH partially updates, DELETE removes), and the status code reports the true outcome so a client can react correctly without parsing prose.
Think of it as
Think of a REST API like a library catalog, not a set of librarian commands. You do not ask a librarian to "performBookLookup" — you point at a shelf location (/books/isbn/9780134685991) and the action you want (checking it out, returning it, or reading its record) is a small, separate verb applied to that fixed address. The URL never changes meaning; only the verb applied to it does.
What we're doing: Model an order resource and its lifecycle using nouns, HTTP verbs and correct status codes instead of verb-shaped endpoints.
- 1
- POST /orders creates a new order — the verb lives in the method, not in the path.
- 6
- 201 Created plus a Location header tells the client exactly where the new resource now lives.
- 19
- 404 reports a client-facing fact (this id does not exist) as a status code the client can branch on, rather than a message buried in a 200 body.
Why this works: Every response here carries its outcome in the status code first — a client can decide what to do (use the body, fix the request, retry) by checking one number before it even parses JSON.
Returning 200 OK for every response and burying the real outcome in the body
Wrong
Better
What you see: Generic HTTP tooling (caches, retry middleware, monitoring dashboards, API gateways) sees 200 and treats the call as a success — a failed lookup silently inflates a service's success-rate metric and never triggers a client's built-in error handling.
Why: The status code is the layer that infrastructure between client and server actually reads. A body-only error is invisible to anything that does not parse this specific API's JSON shape, which is every generic HTTP tool in the request path.
- 2xx Success — 200 OK, 201 Created, 204 No Content
- 3xx Redirection — 301 Moved, 304 Not Modified
- 4xx Client error — 400, 401, 403, 404, 409, 422 — fix the request
- 5xx Server error — 500, 503 — retry with backoff
HTTP methods on a resource: verb, safety and idempotency
Together
Status code families a client actually branches on
Together
Remember: Model nouns as resources (/orders/42) and let the HTTP method carry the verb — GET/PUT/DELETE are idempotent, POST/PATCH are not, and the status code (not the body) is what tells a client the true outcome.
See also: api gateway responsibilities

