REST API design
Resource modeling, cursor vs offset pagination, consistent error envelopes, versioning, idempotency keys for unsafe operations. Contracts outlive implementations.
The mental model
An API is a menu in a restaurant, not a tour of the kitchen. The menu names dishes the customer can order — it does not expose the walk-in fridge, the prep schedule, or which supplier the tomatoes came from. When the kitchen reorganises, the menu stays the same. When the menu changes, every customer has to be told.
REST applies that to HTTP: you expose **resources** (nouns) that clients address by URI and manipulate with the standard verbs. POST /orders creates an order. GET /orders/42 reads it. The client never learns whether orders live in one table, three tables, or a document store — and that ignorance is the product, because it is what lets you change the storage without breaking anyone.
**Why this exists — what breaks without it.** Without resource discipline you get an RPC-over-HTTP sprawl: POST /getOrderById, POST /getOrdersForUserWithStatus, POST /updateOrderStatusAndNotify. Every new requirement adds an endpoint, nothing is cacheable, and the surface grows without bound. Without a versioning strategy, the first breaking change takes down every mobile app in the field, permanently, because a phone in a drawer never upgrades. Without pagination discipline, GET /orders works beautifully in staging with 500 rows and times out in production with 40 million. Without idempotency keys, a client retry after a network timeout risks a double charge whenever the first request actually succeeded. Without a consistent error envelope, every client writes bespoke parsing for every endpoint.
The single sentence that captures the discipline: contracts outlive implementations. You will rewrite the service; you cannot rewrite the clients.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision