# REST architectural constraints explained

> What are the constraints that define REST, and why do statelessness and the uniform interface matter?

Canonical: https://www.internhack.in/learn/interview/api-design-interview/api-rest-constraints
Last updated: 2026-11-28

Difficulty: Beginner

## Question

What are the constraints that define REST, and why do statelessness and the uniform interface matter?

## Answer

REST is often used loosely to mean any JSON over HTTP API, but it is actually an architectural style from Roy Fielding's dissertation. The value of knowing the constraints is that each one buys you a specific property, and interviewers want to hear you connect constraint to benefit.

The first constraint is client-server separation. The UI and the data storage concerns evolve independently. A mobile app, a web app and a partner can all consume the same backend as long as the contract holds.

The second is statelessness. Each request must carry everything the server needs to process it: credentials, parameters, context. The server does not remember your previous request in a session. Think of ordering at a busy counter where every order slip is complete by itself, versus a waiter who has to remember your table history. Stateless servers are trivial to scale horizontally because any instance can serve any request, and a crash loses no session data. The cost is slightly larger requests, usually a bearer token in the Authorization header. Note that stateless does not mean the application has no state; state lives in the database or on the client, not in server memory tied to a connection.

The third is cacheability. Responses must declare whether they can be cached, using Cache-Control, ETag and Last-Modified. This is how CDNs and browsers take load off your servers.

The fourth is the uniform interface, the constraint that most distinguishes REST. It has four parts. Resource identification: everything is a resource addressed by a URI, such as /orders/42. Manipulation through representations: the client works with a JSON or XML representation of the resource and sends it back to change it. Self-descriptive messages: each message says how to interpret it, through media types, methods and status codes. And hypermedia as the engine of application state, HATEOAS, where responses include links to the next possible actions. In practice most public APIs skip full HATEOAS, which is why Richardson's maturity model calls them level 2.

The fifth is the layered system. A client cannot tell whether it talks to the origin server or to a load balancer, gateway, or CDN in between. That enables API gateways, WAFs and caches without client changes.

The optional sixth is code on demand, where the server can send executable code such as JavaScript. Almost nobody discusses it in interviews.

Common edge case questions: Is a session cookie RESTful? Strictly, server-side session state violates statelessness, although a self-contained signed token is fine. Is RPC-style /createUser REST? No, because the verb is in the URI rather than in the method acting on a resource. Is a POST that searches with a big body REST? It is a pragmatic exception, since GET bodies are unreliable.

So when someone asks why REST scales, the crisp answer is: statelessness gives horizontal scaling, cacheability gives read offloading, the uniform interface gives decoupling and predictability, and layering gives infrastructure flexibility.

## Code examples

### Stateless request carrying all context

```
GET /orders?status=paid&limit=20 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOi...
Accept: application/json
```

Any server instance can handle this request because identity and parameters travel with it; no server-side session lookup is needed.

## Key points

- REST is a style, not a protocol or a standard.
- Statelessness is about server-side session state, not about having no data.
- Most so-called REST APIs are level 2 on the Richardson model, resources plus verbs.
- Layering is what makes gateways and CDNs transparent.
- Idempotent and safe methods help caches and retries work correctly.

## Common follow-up questions

- Is JWT authentication compatible with statelessness?
- What is HATEOAS and why is it rarely used?
- How does statelessness help autoscaling?
- What is the Richardson maturity model?

## Interview tips

- Tie every constraint to a benefit rather than reciting a list.
- Be ready to admit that real world APIs bend rules pragmatically.

## Concepts covered

REST, statelessness, uniform interface, resources

Previous: [What makes an API good? Principles of API design](https://www.internhack.in/learn/interview/api-design-interview/api-what-makes-good-api) · Next: [Resource naming and URL design conventions](https://www.internhack.in/learn/interview/api-design-interview/api-resource-naming) · [All of API Design](https://www.internhack.in/learn/interview/api-design-interview)

## More API Design questions

- [HTTP methods: safe vs idempotent](https://www.internhack.in/learn/interview/api-design-interview/api-http-methods-idempotency)
- [PUT vs PATCH vs POST: when to use which](https://www.internhack.in/learn/interview/api-design-interview/api-put-vs-patch-vs-post)
- [Choosing the right HTTP status codes](https://www.internhack.in/learn/interview/api-design-interview/api-status-codes)
- [Designing error responses with RFC 9457 problem details](https://www.internhack.in/learn/interview/api-design-interview/api-error-format-problem-details)
- [Pagination: offset vs cursor (keyset) trade-offs](https://www.internhack.in/learn/interview/api-design-interview/api-offset-vs-cursor-pagination)
- [Filtering, sorting, searching and field selection](https://www.internhack.in/learn/interview/api-design-interview/api-filtering-sorting-fields)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [API Design](https://www.internhack.in/learn/interview/api-design-interview)
