1.REST fundamentals: resources, HTTP semantics and status codes
A 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.
Key features
- A resource is a noun addressed by a URL (/orders/42) — the HTTP method supplies the verb, so /getOrders or /deleteOrder/42 duplicates the verb the method already carries
- GET, PUT, DELETE and HEAD are idempotent by definition — calling them once or five times leaves the server in the same state; POST and PATCH are not, by default
- GET and HEAD are also safe — they must not change server state at all, which is what lets proxies and browsers cache or prefetch them freely
- 2xx means success (200 OK, 201 Created, 204 No Content); 4xx means the client's request was the problem (400 Bad Request, 401 Unauthenticated, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable Entity); 5xx means the server failed even though the request was valid
- 201 Created should return a Location header pointing at the new resource's URL, rather than only a 200 with a body
- Idempotency (an operation is safe to retry without a second effect) matters most for POST, since PUT/DELETE already get it for free from the method definition — full idempotency-key mechanics are a separate concept
HTTP methods on a resource: verb, safety and idempotency
Status code families a client actually branches on
- 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
Command
GET /orders -- list orders
POST /orders -- create an order
GET /orders/{id} -- read one order
PUT /orders/{id} -- replace one order
PATCH /orders/{id} -- partially update one order
DELETE /orders/{id} -- delete one orderModel 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.