May 30, 2024
Designing RESTful APIs That Don't Suck
Bad API design creates technical debt that lasts years. Here's what we learned.
Be Consistent
Pick a pattern and stick to it:
- Plural nouns for collections:
/items, not/item - Nested resources:
/orders/123/items - Standard HTTP methods: GET, POST, PUT, DELETE
Version Early
We started at /api/v1/. When we need breaking changes, we'll add /api/v2/ and maintain both.
Validate Input
Every request. Every field. Return clear error messages with field-level details.
{
"error": "Validation failed",
"details": {
"email": "Invalid email format",
"price": "Must be greater than 0"
}
}
Paginate Everything
Lists grow. Don't return 10,000 items. Use cursor-based pagination for consistency.
Document It
We use Swagger/OpenAPI. Auto-generated docs from code. Stays up to date automatically.
The Payoff
Good API design makes integration painless. Bad design makes it hell.
Choose wisely.