Bookmarks

REST — REST

Representational State Transfer

An architectural style for distributed systems: client and server communicate through a uniform interface (usually over HTTP), and every piece of information is an addressable resource.

Also: REST API, RESTful API, RESTful

checked 9 Nov

All terms

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:

ConstraintWhat it gives
Client–serverseparates the interface from data storage: components evolve independently
Statelessnesseach request is self-contained and the server keeps no client session, so scaling is easier
Cachingresponses are marked cacheable or not, so repeat requests can be skipped
Uniform interfaceresources, representations, self-descriptive messages and HATEOAS simplify and decouple the parts of the system
Layered systemproxies, gateways and load balancers are invisible to the client
Code on demandoptional; 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.

httpOne resource, standard HTTP methods
GET    /orders/1042        # read an orderPOST   /orders             # create a new onePUT    /orders/1042        # replacePATCH  /orders/1042        # change part of itDELETE /orders/1042       # delete

HTTP 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 pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • APIapplication programming interface

    An API is any programming interface at all; REST is just one way to build an API over HTTP.

  • GraphQL

    GraphQL is a separate query language with a single entry point; REST is a style with a different address for each resource.

  • WebSocket protocol

    WebSocket is a persistent two-way connection for exchanging messages; REST is requests and responses over HTTP.

In depth in the references

where the topic is covered in detail