An API is RESTful when it conforms to the architectural constraints of Representational State Transfer (REST), a style defined by Roy Fielding in his 2000 doctoral dissertation. In practice, this means the API uses HTTP methods explicitly, exposes resources via URIs, is stateless, and supports a uniform interface—most commonly JSON over HTTP.
Background: Where REST Came From
Roy Fielding introduced REST in Chapter 5 of his dissertation as a set of constraints for distributed hypermedia systems. He was one of the principal authors of the HTTP specification, and REST was intended to describe the architectural style that made the early web scalable. REST is not a protocol or a standard; it is an architectural style. An API can be “RESTful” to varying degrees, and many APIs that call themselves RESTful only implement some of the constraints.
The term is often contrasted with SOAP (Simple Object Access Protocol), a more rigid XML-based protocol, and with newer styles such as GraphQL and gRPC. REST’s popularity grew because it leverages the existing infrastructure of the web—HTTP, URIs, and standard media types—without requiring custom protocols or heavy tooling.
The Six Architectural Constraints
Fielding defined six constraints. An API that satisfies all of them is considered RESTful in the strict sense. Most real-world “RESTful” APIs relax one or two, particularly the hypermedia constraint.
- Client–server: The client and server are separate concerns. The client handles the user interface and user state; the server handles data storage and business logic. They communicate through a uniform interface, allowing each to evolve independently.
- Stateless: Each request from client to server must contain all the information needed to understand and process it. The server does not store client context between requests. Session state is kept entirely on the client. This improves reliability and scalability because any server can handle any request.
- Cacheable: Responses must explicitly or implicitly label themselves as cacheable or non-cacheable. Caching reduces client–server interactions and improves performance. HTTP headers like
Cache-Control,ETag, andLast-Modifiedare used for this. - Uniform interface: This is the central constraint and includes four sub-constraints: identification of resources (each resource has a URI), manipulation of resources through representations (clients modify resources by sending representations), self-descriptive messages (each message includes enough information to describe how to process it), and hypermedia as the engine of application state (HATEOAS—responses include links to related actions).
- Layered system: A client cannot ordinarily tell whether it is connected directly to the end server or to an intermediary such as a proxy, gateway, or load balancer. Layers can be added for security, caching, or load balancing without affecting the client.
- Code on demand (optional): Servers can temporarily extend client functionality by transferring executable code, such as JavaScript. This is the only optional constraint.
How RESTful APIs Work in Practice
RESTful APIs use HTTP methods to indicate the desired action on a resource. The most common mapping is:
GET— retrieve a representation of a resource. Should be safe (no side effects) and idempotent.POST— create a new resource or submit data for processing. Not idempotent.PUT— replace a resource entirely with the provided representation. Idempotent.PATCH— partially modify a resource. Not necessarily idempotent, though it can be designed to be.DELETE— remove a resource. Idempotent.
Resources are identified by URIs. For example, /users/123 identifies a specific user, while /users identifies the collection. A well-designed RESTful API uses nouns in URIs, not verbs; the HTTP method supplies the verb. So GET /users/123 retrieves user 123, and DELETE /users/123 deletes that user. Avoid URIs like /getUser?id=123, which embed the action in the path.
Representations are typically JSON or XML. The client and server exchange representations of resource state. For example, a GET request might return:
{
"id": 123,
"name": "Alice",
"email": "alice@example.com"
}
Status codes communicate outcomes. 200 OK for success, 201 Created after a POST that creates a resource, 204 No Content after a successful DELETE, 400 Bad Request for client errors, 404 Not Found when a resource does not exist, and 500 Internal Server Error for server faults. Using standard codes correctly is a hallmark of a well-designed RESTful API.
HATEOAS and the Uniform Interface
HATEOAS (Hypermedia as the Engine of Application State) is the most misunderstood constraint. It means that responses should include hypermedia links that guide the client through available actions. For example, a response for an order might include links to cancel or pay depending on the order’s state. This allows servers to evolve their URI structure without breaking clients, because clients discover links dynamically rather than hard-coding them.
In practice, few APIs implement HATEOAS fully. Many APIs that call themselves RESTful are more accurately described as “HTTP APIs” or “REST-like.” This is not necessarily a problem—HATEOAS adds complexity, and many teams choose to document endpoints statically instead. However, strictly speaking, an API without HATEOAS does not satisfy the uniform interface constraint completely.
Common Misconceptions and Pitfalls
Several myths surround RESTful design. One is that REST requires JSON. In fact, REST is agnostic about format; JSON is simply the most common choice today. XML, HTML, and other media types are equally valid. Another myth is that REST requires versioning in the URI (e.g., /v1/users). Versioning is a practical concern, not a REST constraint; some APIs use custom media types or headers for versioning instead.
Another common pitfall is confusing REST with CRUD. While RESTful APIs often map to create, read, update, and delete operations, REST is broader. It is about resources and representations, not just database operations. Similarly, using HTTP methods incorrectly—such as using GET for destructive actions—violates the safe method constraint and can cause problems with caching and crawlers.
Statelessness is often compromised by server-side sessions. If an API stores session state on the server between requests, it is not stateless. Statelessness improves scalability because any server instance can handle any request, which is essential for horizontal scaling in cloud environments.
REST vs. Other API Styles
REST is often compared with GraphQL and gRPC. GraphQL allows clients to request exactly the data they need in a single query, which can reduce over-fetching and under-fetching compared to REST. However, GraphQL typically uses a single endpoint and POST requests, so it does not follow REST’s resource-oriented URI design. gRPC uses HTTP/2 and Protocol Buffers for high-performance remote procedure calls; it is not RESTful because it exposes methods, not resources, and does not use HTTP verbs in the RESTful sense.
SOAP is a protocol with strict standards for messaging, security, and transactions. REST is an architectural style that is simpler and more flexible but lacks built-in standards for those concerns. The choice between them depends on requirements such as performance, tooling, and interoperability.
Frequently Asked Questions
Is REST the same as HTTP?
No. REST is an architectural style, while HTTP is a protocol. REST can be implemented over other protocols, though HTTP is by far the most common because REST’s constraints align well with HTTP’s features.
Does a RESTful API have to use JSON?
No. REST does not mandate any specific data format. JSON is popular because it is lightweight and easy to parse, but XML, HTML, and other formats are also valid.
What does stateless mean in REST?
Stateless means the server does not store any client context between requests. Each request must contain all the information needed to process it, such as authentication tokens or parameters. This improves scalability and reliability.
Can a RESTful API use sessions?
Strictly speaking, no. Using server-side sessions violates the stateless constraint. However, many APIs use tokens (like JWT) that are stored on the client and sent with each request, which is stateless.
What is HATEOAS and do I need it?
HATEOAS stands for Hypermedia as the Engine of Application State. It means responses include links to related actions. While it is a core part of the uniform interface constraint, many practical APIs omit it. Whether you need it depends on how strictly you want to adhere to REST and how much you value discoverability.
Why do some APIs called RESTful not follow all constraints?
Because REST is a style, not a standard, and full adherence—especially to HATEOAS—can add complexity. Many teams adopt the most practical constraints (statelessness, resource URIs, HTTP methods) and skip others. Such APIs are often called “RESTful” in casual usage even if they are not strictly REST.