Constraints of REST API: 6 Rules Every Developer Should Know
REST APIs power everything from mobile applications and SaaS platforms to cloud-native infrastructure. However, simply exposing endpoints over HTTP does not make an API RESTful.
To build scalable, maintainable, and reliable systems, developers must understand the constraints of REST API architecture. These constraints were introduced by Roy Fielding in his doctoral dissertation and define what qualifies an API as truly RESTful.
Understanding these principles is especially important for software engineers, DevOps professionals, platform engineers, and students preparing for API design interviews.
If you're new to REST, start with this guide on What is REST API before diving into the architectural constraints.
Why REST API Constraints Matter
The constraints of REST API architecture are not arbitrary rules. They exist to solve common problems in distributed systems.
When implemented correctly, these constraints help APIs become:
- Scalable under increasing traffic
- Easier to maintain and evolve
- More reliable across different clients
- Better suited for caching and performance optimization
- Easier to integrate with external systems
These characteristics explain why REST remains one of the most widely adopted architectural styles for web APIs.
What Are the 6 Constraints of REST API?
A RESTful API must follow six architectural constraints:
- Client-Server Architecture
- Statelessness
- Cacheability
- Layered System
- Code on Demand (Optional)
- Uniform Interface
Let's examine each constraint in detail.
1. Client-Server Architecture
The client-server constraint separates the user interface from data storage and business logic.
In this model:
- The client sends requests
- The server processes requests
- Both can evolve independently
For example, a mobile application can be redesigned without modifying backend services. Similarly, backend services can be upgraded without changing the client application.
This separation of concerns improves maintainability and allows teams to work independently.
2. Statelessness
Statelessness is one of the most important REST constraints.
A stateless API does not store client context between requests. Every request must contain all information required to process it.
For example, if a client requests a user profile, the request should include:
- Authentication token
- Request parameters
- Resource identifier
The server should not depend on information from previous requests.
Benefits of statelessness include:
- Better horizontal scalability
- Simpler load balancing
- Improved fault tolerance
- Reduced server-side complexity
Real-World Example
Cloud platforms such as AWS and Kubernetes rely heavily on stateless communication patterns. Since requests can be processed by any available server instance, services can scale efficiently behind load balancers.
To understand what information travels in each request, see the guide on the anatomy of a REST API request.
3. Cacheability
REST responses should explicitly indicate whether they can be cached.
Caching allows clients, browsers, CDNs, and intermediary systems to reuse previously fetched responses instead of repeatedly contacting the origin server.
Benefits include:
- Faster response times
- Reduced server load
- Lower network usage
- Improved user experience
A common example is a product catalog API. If product data changes infrequently, caching can significantly reduce the number of requests reaching backend services.
Cache behavior is typically controlled through HTTP headers and response metadata.
4. Layered System
The layered system constraint allows an API architecture to be composed of multiple intermediary layers.
A client does not need to know whether it is communicating directly with the application server or through several intermediaries.
Common layers include:
- CDN
- API Gateway
- Load Balancer
- Reverse Proxy
- Authentication Service
- Application Server
For example, in a cloud-native environment, a request may pass through:
- CDN
- API Gateway
- Load Balancer
- Kubernetes Ingress
- Backend Service
This approach improves security, scalability, and maintainability without affecting client behavior.
5. Code on Demand (Optional)
Code on Demand is the only optional REST constraint.
It allows a server to provide executable code that extends client functionality.
Historically, this was often implemented using JavaScript delivered by web servers.
Potential benefits include:
- Reduced client complexity
- Dynamic feature delivery
- Enhanced user interactions
Despite being part of the REST architecture, many modern REST APIs do not use Code on Demand because it introduces additional security and maintainability considerations.
6. Uniform Interface
The Uniform Interface constraint is what makes REST APIs predictable and easy to consume.
It standardizes how clients interact with resources regardless of implementation details.
This constraint consists of four principles.
Identification of Resources
Every resource must have a unique identifier.
Resources are typically identified using URIs.
Examples include:
/users/123
/orders/456
/products/789
Understanding the difference between identifiers is important when designing APIs. Learn more about URI vs URL vs URN.
You can also explore what constitutes a resource in REST API design.
Manipulation of Resources Through Representations
Clients interact with resources using representations such as JSON or XML.
For example:
{
"id": 123,
"name": "John Doe"
}
The client modifies the representation and sends it back to the server using HTTP methods such as:
- GET
- POST
- PUT
- PATCH
- DELETE
To understand how these operations work, see:
- GET Method in REST API
- POST Method in REST API
- PUT Method in REST API
- PATCH Method in REST API
- DELETE Method in REST API
Self-Descriptive Messages
Every request and response should contain enough information for recipients to understand how the message should be processed.
Examples include:
- HTTP methods
- Content-Type headers
- Authentication information
- Status codes
- Response headers
This allows clients and servers to communicate without relying on hidden assumptions.
Learn more about:
Hypermedia as the Engine of Application State (HATEOAS)
HATEOAS allows clients to discover available actions through hyperlinks provided in API responses.
For example:
{
"id": 123,
"name": "John Doe",
"links": [
{
"rel": "orders",
"href": "/users/123/orders"
}
]
}
Instead of hardcoding workflows, clients follow links exposed by the server.
Although HATEOAS is part of REST's formal definition, many modern APIs implement it only partially.
Which REST Constraint Is Most Important?
There is no official ranking among the six constraints.
However, many API architects consider the Uniform Interface constraint the defining characteristic of REST because it standardizes communication between clients and servers.
Statelessness is also critical because it enables horizontal scaling and simplifies distributed systems.
An API that ignores major REST constraints may still function correctly, but it cannot be considered fully RESTful.
Are APIs Still RESTful If They Ignore a Constraint?
Not necessarily.
According to Roy Fielding's REST architectural style, all mandatory constraints must be satisfied for an API to be considered fully RESTful.
The only optional constraint is Code on Demand.
If an API violates constraints such as Statelessness or Uniform Interface, it may still be a web API, but it no longer fully adheres to REST principles.
REST API Interview Tip
A common interview question is:
What makes an API RESTful?
A strong answer should mention:
- Client-Server Architecture
- Statelessness
- Cacheability
- Layered System
- Uniform Interface
- Code on Demand (optional)
Interviewers often expect candidates to explain why Statelessness and Uniform Interface are especially important for scalability and interoperability.
Did You Know?
The REST architectural style was introduced by Roy Fielding in his 2000 doctoral dissertation at the University of California, Irvine.
The dissertation remains the authoritative source for REST and is available through Roy Fielding's official website:
Architectural Styles and the Design of Network-based Software Architectures
Frequently Asked Questions
What are the constraints of REST API?
The six constraints of REST API are:
- Client-Server Architecture
- Statelessness
- Cacheability
- Layered System
- Code on Demand (Optional)
- Uniform Interface
An API must follow these constraints to be considered fully RESTful.
Why is statelessness important in REST APIs?
Statelessness allows each request to be processed independently.
This improves scalability, simplifies server design, and enables efficient load balancing across multiple servers.
What are the benefits of cacheable REST APIs?
Cacheable APIs reduce unnecessary network traffic and improve performance.
Proper caching can decrease response times and reduce backend infrastructure load.
How does the layered system constraint improve API design?
A layered architecture enables developers to add security layers, gateways, load balancers, and caching systems without affecting client applications.
This makes systems easier to scale and maintain.
Are all web services REST APIs?
No.
REST is only one architectural style for web services.
Other approaches include:
- SOAP
- GraphQL
- gRPC
Each has different design principles and use cases.
Key Takeaways
The constraints of REST API architecture provide the foundation for building scalable and maintainable web services.
The six constraints are:
- Client-Server Architecture
- Statelessness
- Cacheability
- Layered System
- Code on Demand (Optional)
- Uniform Interface
Understanding these principles helps developers design APIs that are easier to scale, easier to maintain, and more consistent for consumers.
8 free, 100% client-side tools for developers — no signup, no data uploads.
Explore all tools