RESTful API Design Principles
Essential principles for designing clean, consistent, and developer-friendly RESTful APIs including naming conventions, versioning, pagination, and error responses.
Why Good API Design Matters
A well-designed API is the difference between a product developers love and one they dread. After building dozens of APIs, here are the principles I follow.
1. URL Naming Conventions
✅ GET /api/v1/users
✅ GET /api/v1/users/123
✅ GET /api/v1/users/123/orders
✅ POST /api/v1/users
❌ GET /api/getUsers
❌ GET /api/user_list
❌ POST /api/createUser
Rules:
- Use plural nouns, not verbs
- Use kebab-case for multi-word resources
- Nest related resources logically
2. Consistent Response Format
{
"success": true,
"data": {
"id": 123,
"name": "John"
},
"meta": {
"page": 1,
"total": 50
}
}
3. Proper HTTP Status Codes
| Code | When to Use |
|---|---|
| 200 | Successful GET/PUT |
| 201 | Successful POST (created) |
| 204 | Successful DELETE |
| 400 | Bad request (validation error) |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not found |
| 429 | Rate limited |
| 500 | Server error |
4. Pagination
Always paginate list endpoints:
GET /api/v1/users?page=1&limit=20&sort=-created_at
5. Versioning
Use URL-based versioning for simplicity:
/api/v1/users
/api/v2/users
Conclusion
Consistency is the most important principle. Pick conventions and stick with them across your entire API surface.