How to design clean, predictable, and developer-friendly APIs.
A well-designed API feels obvious. A poorly designed one creates frustration for every consumer.
Prefer nouns over verbs:
| Bad | Good |
|---|---|
/getUsers | /users |
/createPost | /posts |
/deleteComment | /comments/{id} |
Use HTTP methods correctly:
GET → retrievePOST → createPUT / PATCH → updateDELETE → removeAlways return a predictable structure:
{
"data": { ... },
"meta": {
"page": 1,
"total": 42
},
"error": null
}
On error:
{
"data": null,
"error": {
"code": "VALIDATION_ERROR",
"message": "Email is required"
}
}
Two common approaches:
/v1/usersAccept: application/vnd.api.v1+jsonURL versioning is simpler for most teams.
Standard query parameters:
GET /posts?page=2&limit=20&sort=-createdAt&status=published
| Code | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 204 | No Content |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 422 | Unprocessable Entity |
| 500 | Internal Server Error |
Good API design is about empathy. Design for the developer who will consume your API at 2 a.m. while debugging production.