Understanding API Design Principles
After 12 years of building APIs that developers actually want to use, I've learned that good API design isn't about following every REST convention to the letter. It's about creating something that feels intuitive and doesn't make developers want to throw their laptops out the window.
The API That Made Me Cry (And Not in a Good Way)
I once had to integrate with an API that returned user data like this: {userName: 'John', userEmail: 'john@example.com'}. But then for posts, it was {post_title: 'Hello', post_content: 'World'}. Inconsistent naming, inconsistent structure, and zero documentation. I spent more time guessing than coding.
The Golden Rule: Be Predictable
If your API follows patterns, developers can guess how it works. If I see GET /users, I should be able to guess that GET /users/123 gets a specific user. No surprises, no "gotcha" moments.
HTTP Methods That Actually Make Sense
I've seen APIs where POST /users/delete was a thing. Just... why? Use the right verbs:
- GET /users - "Give me all users"
- POST /users - "Create a new user"
- PUT /users/123 - "Replace this user completely"
- PATCH /users/123 - "Update just these fields"
- DELETE /users/123 - "Remove this user"
The Response Format That Doesn't Suck
I've seen APIs return data in 47 different formats. Pick one and stick with it. Here's what works:
{
"success": true,
"data": {
"id": 123,
"name": "John Doe",
"email": "john@example.com"
},
"errors": null,
"meta": {
"timestamp": "2024-12-10T10:30:00Z",
"request_id": "req_abc123"
}
}Error Messages That Help (Not Hurt)
"Error 500" tells me nothing. "Invalid email format" tells me exactly what to fix. Be specific, be helpful, and for the love of all that is holy, include the field name that's causing the problem.
Versioning: The Thing Everyone Gets Wrong
I've seen APIs versioned in URLs, headers, query params, and even in the request body. Pick one method and use it consistently. I prefer URL versioning because it's obvious:
/api/v1/users- Clear, obvious, works with caching/api/v2/users- Breaking changes? New version/api/v1/users?version=2- Just... no. Don't do this.
Security: Not Optional
I've seen APIs with no authentication, APIs that accept SQL injection like it's a feature, and APIs that log passwords in plain text. Don't be that API. Use HTTPS, validate everything, rate limit appropriately, and for the love of all that is holy, don't log sensitive data.
Documentation That Doesn't Lie
I've spent hours debugging issues that turned out to be documentation errors. If your docs say the API returns a user object with an "email" field, make sure it actually does. Include real examples, not fake ones. Show error responses. Include rate limits. Be honest about what your API does and doesn't do.
Testing: The Safety Net
Test your API like you hate it. Send malformed data. Send too much data. Send data in the wrong format. Test rate limits. Test authentication. Test edge cases. Your users will find every way to break your API, so find them first.
Remember: good APIs are built by developers who remember what it's like to be on the consuming end. Be the API you'd want to integrate with.
About the Author
Ryan Chen is the CTO of Korq, with 12+ years of experience in software architecture and API design.