HTTP API design #
An HTTP API gives clients a way to request data or change system state. Its contract includes inputs, authorization, response formats, failure behavior, and retry rules. Use these guides to define that contract and trace a request from the client to its observable result.
This section contains ten topic guides. Their examples illustrate decisions to review for your own service; they are not a complete production implementation.
What You'll Learn #
Choose a guide for the behavior you need to define:
Core Topics #
- Versioning - How to evolve your API without breaking existing clients
- Error Handling - Standardized approaches to communicating failures
- Authentication - Securing your API with modern authentication methods
- Filtering - Enabling clients to query exactly the data they need
- Pagination - Efficiently handling large datasets
- Rate Limiting - Protecting your infrastructure from abuse
- Content Negotiation - Supporting multiple data formats
- Idempotency - Making operations safe to retry
- Caching - Leveraging HTTP caching for performance
- Observability - Logging, monitoring, and debugging in production
REST Fundamentals #
REST (Representational State Transfer) is an architectural style described in Roy Fielding's dissertation. HTTP is a protocol often used to implement it. RFC 9110 defines HTTP semantics, including methods, status codes, and representation metadata; it does not define REST.
The Six Constraints #
Roy Fielding's original dissertation defined REST with six architectural constraints:
- Client-Server - Separation of concerns between UI and data storage
- Stateless - Each request contains all information needed to understand it
- Cacheable - Responses must define themselves as cacheable or not
- Uniform Interface - Consistent way to interact with resources
- Layered System - Client can't tell if connected directly to server
- Code on Demand (optional) - Servers can extend client functionality
Getting Started #
If you're new to API design, we recommend starting with these guides in order:
- Start with Error Handling to understand how to communicate problems
- Move to Authentication to learn about securing your API
- Then Versioning to plan for evolution
- Finally Caching to make it fast
For specific challenges:
- Building a search API? → Read Filtering and Pagination
- Payment or transaction API? → Focus on Idempotency
- Public API with many users? → Start with Rate Limiting
- Need to debug issues? → Jump to Observability
Standards and Specifications #
These guides reference and build upon established web standards:
- HTTP semantics — RFC 9110
- HTTP caching — RFC 9111
- HTTP/1.1 message syntax — RFC 9112
- HTTP/2 — RFC 9113
- HTTP/3 - RFC 9114 (QUIC-based HTTP)
- URI - RFC 3986 (Uniform Resource Identifiers)
- JSON - RFC 8259 (JavaScript Object Notation)
- OAuth 2.0 - RFC 6749 (Authorization framework)
- JWT - RFC 7519 (JSON Web Tokens)
- Problem Details — RFC 9457, which replaces RFC 7807
Beyond This Guide #
API design is a vast topic. After mastering these fundamentals, consider exploring:
- GraphQL for query flexibility
- gRPC for high-performance RPC
- WebSockets for real-time bidirectional communication
- Server-Sent Events for server-push updates
- Webhooks for event-driven integrations
Choose a protocol from the interaction your clients need, then document its connection, authorization, retry, and failure behavior.