Study smarter with Fiveable
Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.
API design isn't just about making endpoints work—it's about creating contracts that other developers (and your future self) can rely on. In this course, you're being tested on your ability to think systematically about abstraction, modularity, and interface design. A well-designed API embodies these principles: it hides implementation details, exposes clear contracts, and enables components to evolve independently. Whether you're building REST services, library interfaces, or internal module boundaries, these principles determine whether your code scales gracefully or becomes a maintenance nightmare.
The concepts here connect directly to software engineering fundamentals: coupling and cohesion, separation of concerns, defensive programming, and the principle of least surprise. When exam questions ask you to critique an API design or propose improvements, they're really testing whether you understand how design decisions ripple through entire systems. Don't just memorize these principles—know what problem each one solves and when you'd prioritize one over another.
Great APIs minimize cognitive load. The principle of least astonishment means developers should be able to predict behavior without consulting documentation for every call.
{ "data": [...], "meta": {} }, all endpoints should follow this patternuserId everywhere, not user_id in some places and userID in others)/users/{id}/orders immediately communicate resource relationships/invoices (not /getInvoices) since HTTP methods convey the actiontransaction beats txn for readability and searchabilityCompare: Naming conventions vs. Documentation—both reduce developer confusion, but naming prevents the need to check docs in the first place while documentation handles edge cases and complex workflows. If an exam asks about "self-documenting APIs," naming is your primary example.
APIs are contracts. Breaking changes destroy trust and create integration nightmares. These principles help you evolve without breaking existing clients.
/v1/users, /v2/users) is explicit and easy to route but clutters URLsAccept: application/vnd.api+json;version=2) keeps URIs clean but is less discoverable/users?version=2) offers a middle ground but can be overlookedCompare: URI versioning vs. Header versioning—URI is more visible and cache-friendly, headers are more RESTful and flexible. For FRQs asking about trade-offs, discuss discoverability vs. REST purity.
APIs must fail gracefully. Defensive programming at the interface level means anticipating misuse and communicating problems clearly.
"email" field must be valid email format{ "error": { "code": "VALIDATION_ERROR", "message": "Invalid input", "details": [...] } }
Compare: Error handling vs. Security—both involve anticipating problems, but errors help legitimate users recover while security prevents malicious access. Both require consistent implementation across all endpoints.
API design decisions have systemic implications for how applications scale and how teams can work independently.
GET (read), POST (create), PUT/PATCH (update), DELETE (remove)/users/{id}/posts/{postId}/commentsGET /users?page=2&limit=50ETag, Cache-Control) reduce redundant server processingCompare: RESTful statelessness vs. Modularity—both enable horizontal scaling, but statelessness operates at the request level (any server can handle any request) while modularity operates at the service level (teams can deploy independently). Both reduce coupling.
| Concept | Best Examples |
|---|---|
| Developer Experience | Consistent naming, intuitive endpoints, comprehensive documentation |
| Contract Stability | Semantic versioning, backward compatibility, deprecation windows |
| Defensive Design | Standardized errors, input validation, authentication |
| REST Architecture | Stateless requests, HTTP method semantics, resource-based URIs |
| Scalability | Pagination, caching, rate limiting |
| Modularity | Separation of concerns, loose coupling, single responsibility |
| Security | OAuth/JWT, HTTPS, least privilege |
| Versioning Approaches | URI versioning, header versioning, query parameters |
Which two principles both aim to reduce cognitive load for API consumers, and how do they differ in approach?
You need to add a required field to an existing endpoint's response. Using semantic versioning, what type of version bump does this require, and why?
Compare and contrast URI versioning with header-based versioning. In what scenario would you choose each?
An API returns 500 Internal Server Error with the message "Something went wrong" for all failures. Which principles does this violate, and how would you redesign the error handling?
If an FRQ asks you to design an API that multiple teams will consume independently, which three principles would you prioritize and why?