HomeBytesheetsRoadmapsUI TemplatesUI ToolsStack Discussion
3 Topics
Chapter•160 Minutes

REST Architectural Style

Understand what REST actually means and distinguish REST constraints from common HTTP API habits.

REST Is an Architectural Style

What REST Really Means

REST stands for Representational State Transfer. It was introduced by Roy Fielding as an architectural style based on constraints for distributed systems.

A RESTful system is not simply an API that uses JSON, HTTP, and URLs. REST has architectural constraints including client-server separation, statelessness, cacheability, a uniform interface, layered systems, and optionally code-on-demand. HATEOAS is part of the uniform-interface constraint.

Many APIs are better described as HTTP APIs rather than strictly RESTful APIs because they use HTTP but do not implement all REST constraints. This distinction matters when discussing architecture precisely.

REST Architectural Constraints
Key Takeaways
  • REST is an architectural style, not a framework.
  • JSON is not a REST requirement.
  • HTTP APIs and RESTful APIs are not always synonymous.

The REST Constraints in Depth

Client-server: UI concerns and data concerns are separated.

Stateless: Every request contains the information required to process it. The server does not rely on conversational session state stored between requests.

Cacheable: Responses explicitly or implicitly indicate whether they may be cached.

Uniform interface: Resources are identified consistently, representations are transferred, messages are self-descriptive, and hypermedia can drive application state.

Layered system: A client does not need to know whether it is communicating directly with the origin server or through proxies, gateways, CDNs, and other intermediaries.

Code-on-demand: Servers may optionally transfer executable code to clients. This constraint is optional.

REST Constraint
Stateless: Each request is self-contained
Application session state should not be required on the server merely to understand a request.
Cacheable: Responses can be cached
Caching improves scalability and latency when correctness permits.
Layered: Intermediaries are allowed
CDNs, proxies, gateways, and load balancers can exist between client and server.
Uniform interface: Consistent interaction model
Resources, representations, messages, and hypermedia form a consistent interface.

Statelessness vs Server Sessions

Statelessness does not mean that the application has no state. Databases contain state, caches contain state, and users have persistent data. It means the server does not depend on hidden conversational state from a previous request to understand the current request.

For example, if a request contains a bearer token, the server can validate the token and determine the caller without depending on an in-memory session on a particular server instance.

Stateless APIs simplify horizontal scaling because any healthy server instance can process the request.

Important

Statelessness is about request context, not the absence of persistent application state.

Stateless Request Processing