Comprehensive guide to REST architecture, constraints, design patterns, and the Richardson Maturity Model.
REST (Representational State Transfer) is an architectural style for designing networked applications. It was introduced by Roy Fielding in his 2000 doctoral dissertation.
REST is not a protocol or standard, but an architectural style. APIs that follow REST principles are called RESTful APIs.
Separation of concerns between client (user interface) and server (data storage). They can evolve independently as long as the interface remains the same.
Each request from client to server must contain all information needed to understand and process the request. Server doesn't store client context between requests.
Responses must define themselves as cacheable or non-cacheable. If cacheable, client can reuse response data for equivalent requests.
Standardized way of communicating between client and server. This is the fundamental constraint that makes REST unique.
Resources are identified by URIs (e.g., /users/123)
Client holds representation (JSON, XML) and has enough info to modify/delete resource
Each message includes enough information to describe how to process it
Hypermedia As The Engine Of Application State - responses include links to related resources
Client cannot tell if it's connected directly to the end server or an intermediary. Allows for load balancers, proxies, gateways, and caches between client and server.
Server can extend client functionality by transferring executable code (e.g., JavaScript). This is the only optional constraint.
Note: Rarely used in modern REST APIs. Most APIs serve data, not executable code. However, web applications loading JavaScript from servers technically implement this.
Leonard Richardson developed a maturity model that breaks down REST into levels, helping understand how "RESTful" an API really is.
POX = Plain Old XML. Uses HTTP as transport only. Single endpoint, single HTTP method (usually POST).
Introduces multiple URIs for different resources. Still uses single HTTP method (POST).
Uses proper HTTP methods (GET, POST, PUT, DELETE) and status codes. Most "RESTful" APIs are here.
Responses include links to related resources. Client discovers available actions from responses.
Level 2 is the sweet spot for most APIs. It provides the core benefits of REST without the complexity of full hypermedia.
Level 3 (HATEOAS) is ideal for public APIs where you want maximum flexibility and discoverability, but adds complexity that many applications don't need.
Avoid Level 0-1 - they miss out on HTTP's capabilities and make APIs harder to use and understand.
| Aspect | REST | GraphQL | gRPC |
|---|---|---|---|
| Protocol | HTTP/HTTPS | HTTP/HTTPS | HTTP/2 |
| Data Format | JSON, XML | JSON | Protocol Buffers |
| Learning Curve | Easy | Medium | Steep |
| Caching | Built-in (HTTP) | Complex | Custom |
| Performance | Good | Good | Excellent |
| Browser Support | Full | Full | Limited |
| Best For | Public APIs, CRUD | Complex queries, mobile | Microservices, real-time |
| Tooling | Mature, widespread | Growing | Specialized |