Designing an API
RequiredRequired
An API is a contract. Clients will depend on every field name, status code and error shape you publish, so design it from the caller’s side: what do they need to do, and what is the least they must know to do it?
Habits that age well
- Name resources with nouns (
/orders/42) and let the HTTP method carry the verb. - Return one error shape everywhere, with a stable machine-readable code next to the human message.
- Paginate every list from day one; adding it later breaks clients.
- Version only when you must break the contract, and keep the old version alive long enough for clients to move.