REST is not a protocol but a set of constraints on how a distributed system is built. Following them gives the system useful properties: simplicity, visibility of interactions, independent evolution of client and server, and scalability. In practice the result is a “REST API”: the client gets data from HTTP addresses and changes it with standard methods, with no extra protocol on top of HTTP.
Six constraints
Roy Fielding derived the style by adding constraints one at a time to an “empty” style; each brings a property, but also a cost:
| Constraint | What it gives |
|---|---|
| Client–server | separates the interface from data storage: components evolve independently |
| Statelessness | each request is self-contained and the server keeps no client session, so scaling is easier |
| Caching | responses are marked cacheable or not, so repeat requests can be skipped |
| Uniform interface | resources, representations, self-descriptive messages and HATEOAS simplify and decouple the parts of the system |
| Layered system | proxies, gateways and load balancers are invisible to the client |
| Code on demand | optional; the client can download and run code (for example, a script) |
“Uniform interface” is the central constraint: every service looks the same to the client. Fielding defines it with four principles: each resource has an identifier; the client works with a representation of the resource (for example, a JSON document); a message carries all the information needed to understand it; and application state changes through hyperlinks in representations (HATEOAS).
Resources and representations
A resource is not a file or a table but whatever the server exposes at an address: a product page, a list of orders, the current weather in Tashkent. One resource can be served in different representations: the same order as JSON for a mobile app and as XML for an old partner.
GET /orders/1042 # read an orderPOST /orders # create a new onePUT /orders/1042 # replacePATCH /orders/1042 # change part of itDELETE /orders/1042 # deleteHTTP methods are not part of REST: the style only requires a uniform interface, and HTTP already provides one. In practice, CRUD actions on resources are mapped to suitable methods, status codes and caching headers.
Where the term comes from
Roy Fielding coined the term in his 2000 dissertation “Architectural Styles and the Design of Network-based Software Architectures” (University of California, Irvine), where chapter 5 describes REST as a style for distributed hypermedia systems.
Sources
the term is written from these pagesVerified 9 Nov