Designing HTTP APIs · core
REST: resources, methods and idempotency
A REST API exposes resources as nouns in URLs and uses HTTP methods for actions, where GET is safe, GET, PUT and DELETE are idempotent, POST is neither, and each request carries everything the server needs (stateless).
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Resources are nouns: /users, /users/42, /users/42/orders. Methods are the verbs: GET read, POST create (or a non-idempotent action), PUT replace, PATCH partial update, DELETE remove.
- Safe = no change on the server (GET, HEAD, OPTIONS). Idempotent = doing it twice has the same effect as once (GET, PUT, DELETE). POST is not idempotent; PATCH is not guaranteed to be.
- PUT replaces the whole resource with what you send; PATCH sends only the changes (e.g. JSON Merge Patch).
- POST create returns 201 Created with a Location header and usually the new resource.
- Stateless: every request carries its auth and context; any server instance can answer it, which makes horizontal scaling easy.
- Actions that are not CRUD: model them as a sub-resource (POST /orders/42/cancellation) or a clear verb endpoint (POST /orders/42/cancel); be consistent.
- Use query parameters for filtering, sorting and pagination: GET /orders?status=paid&sort=-createdAt&limit=20.
The red pen
Common traps: mistake → fix
Mistake: REST means JSON over HTTP
Fix: it is a style: resources, uniform methods, statelessness; many 'REST' APIs are really RPC.
Mistake: DELETE is not idempotent because the second call returns 404
Fix: idempotency is about the server's state, not the response code.
Mistake: Use GET with a body or GET /deleteUser?id=5 for convenience
Fix: GET must be safe; crawlers, prefetchers and caches will call it.
Easy to hard
Questions interviewers ask, easy to hard
- What is REST? What makes an API RESTful?
- Which HTTP methods are safe? Which are idempotent? Why does it matter?
- PUT vs PATCH?
- Design the endpoints for a shift-booking app: shifts, applications, hiring and cancelling.
- How do you model an action like 'cancel order' in REST?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.