Good API Design = Happy Developers

A well-designed API is a product. Your consumers (other developers) will judge your service by how pleasant your API is to use.

The 12 Rules

1. Use Nouns, Not Verbs

โœ… GET /users/123
โŒ GET /getUser?id=123

โœ… POST /orders
โŒ POST /createOrder

2. Use Plural Resource Names

โœ… /users, /products, /orders
โŒ /user, /product, /order

3. HTTP Methods Have Meaning

Method Action Idempotent
GET Read Yes
POST Create No
PUT Replace Yes
PATCH Update partial Yes
DELETE Remove Yes

4. Use Proper Status Codes

200 OK โ€” Success
201 Created โ€” Resource created
204 No Content โ€” Deleted successfully
400 Bad Request โ€” Client error (validation)
401 Unauthorized โ€” Not authenticated
403 Forbidden โ€” Authenticated but not allowed
404 Not Found โ€” Resource doesn't exist
409 Conflict โ€” Duplicate resource
429 Too Many Requests โ€” Rate limited
500 Internal Server Error โ€” Bug on our side

5. Consistent Error Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Email is required",
    "details": [
      { "field": "email", "message": "must be a valid email" }
    ]
  }
}

6. Paginate Everything

GET /users?page=2&limit=20

Response:
{
  "data": [...],
  "meta": {
    "page": 2,
    "limit": 20,
    "total": 156,
    "pages": 8
  }
}

7. Version Your API

https://api.example.com/v1/users

8. Use ISO 8601 for Dates

{ "created_at": "2025-07-14T10:30:00Z" }

9. Filter, Sort, Search via Query Params

GET /products?category=electronics&sort=-price&search=laptop

10. Rate Limit Everything

Include headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1626012345
{
  "id": 123,
  "name": "John",
  "_links": {
    "self": "/users/123",
    "orders": "/users/123/orders"
  }
}

12. Document with OpenAPI/Swagger

Every API should have auto-generated interactive docs. Use tools like swagger-ui or redoc.