REST API Design Best Practices: From URL Structure to Versioning
2025-08-14
REST API Design Best Practices
Designing a good RESTful API is more than slapping CRUD endpoints on top of a database. A well-planned API reduces onboarding time for consumers, lowers the chance of breaking changes, and scales with your product roadmap.
Who is this for? Backend & full-stack developers who already know basic HTTP and are ready to level-up their API craftsmanship.
1. Start With Clear Resource Modeling
- Identify nouns, not verbs – Stick to domain entities (
users,orders,payments). - Use plural lowercase names –
/usersnot/useror/getUsers. - Nest only when ownership is tight –
/users/{id}/postsis OK,/orders/{id}/product/{id}is a smell.
2. Consistent HTTP Methods
| Action | HTTP Verb | Example |
|---|---|---|
| Read | GET | GET /users/42 |
| Create | POST | POST /users |
| Update | PATCH | PATCH /users/42 |
| Delete | DELETE | DELETE /users/42 |
Avoid method tunnelling (POST /deleteUser). The semantics are built into HTTP already.
3. Pagination, Filtering & Sorting
- Pagination –
GET /users?page=2&pageSize=20 - Filtering –
GET /users?role=admin - Sorting –
GET /users?sort=-createdAt(- for DESC)
Return metadata alongside data:
{
"data": [/* ... */],
"meta": {
"page": 2,
"pageSize": 20,
"totalPages": 10,
"totalItems": 194
}
}
4. Robust Error Handling (Problem Details)
Adopt RFC-9457 Problem Details:
{
"type": "https://example.com/errors/validation-error",
"title": "Validation Failed",
"status": 400,
"detail": "Email field must be a valid address",
"instance": "/users"
}
5. Versioning Strategies
- URI versioning –
/v1/users(quick & explicit) - Header versioning –
Accept: application/vnd.myapp.v2+json(cleaner URLs)
Choose ONE and be consistent.
6. Security First
- Always use HTTPS.
- Implement rate-limiting & API keys/OAuth2.
- Never expose raw database IDs if they leak business secrets.
7. Documentation & Tooling
OpenAPI (Swagger) remains the king. Pair it with Redoc or Stoplight for delightful dev-portal experiences.
Further Reading
- Martin Fowler – Richardson Maturity Model
- Phil Sturgeon – API Design Patterns
- Stripe API – gold standard of developer-first APIs.
Happy building!