REST vs HTTP

What is the difference between a REST API and a plain HTTP API?

REST is a popular style of architecting and designing Web applications, which are commonly served over HTTP. But what makes an API RESTful and what is a plain HTTP API? There seems to be a trend of calling any HTTP based API a REST API, even though the API doesn't fulfill all the constraints that REST requires. REST's creator Roy Fielding, also voiced his opinion about this in a blog post on his website:

I am getting frustrated by the number of people calling any HTTP-based interface a REST API.
— Roy Fielding, creator of REST

Let's take a quick look to review, what the REST and HTTP are:

Definitions

Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet. RESTful Web services allow the requesting systems to access and manipulate textual representations of Web resources by using a uniform and predefined set of stateless operations.

The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser.

The REST constraints

REST Web services must follow a set of 6 constraints. We will take a closer look at the following two:

  1. Stateless communication
  2. Uniform interface

Stateless communication means that communication between client and server cannot rely on previous requests. For example: Clients can not ask servers to send them "the next page", because doing so would require that the server maintained some state about, which page the particular client has seen last.

Instead, the uniform interface constraints impose a number of subconstraints namely, identification of resources; manipulation of resources through representations; self-descriptive messages; and hypermedia as the engine of application state(sometimes abbreviated as HATEOAS). This means that Hypertext(or more generally, hypermedia) needs to be the driving mechanism by which clients navigate through the application. Hypermedia is a data format that can be interlinked. HTML with its anchor tags is a good example, but any format with this capability will work.

So, by using hypermedia servers can directly send clients new URIs to navigate to. So instead of storing, which page a client has seen last, a server following a REST design will simply include a link to page 4 if it received a request for page 3. The client can then use it request the next page without the server having to maintain any client state.

REST aims to reduce coupling between client and server, so another big benefit of including hyperlinks to other resources in the response, is that the client does NOT need to know a catalog of available resources up front. It is enough for clients to navigate to the inital service URI and then follow links to other resources. This enables clients and servers to evolve independently because resources can be discovered and do not need to be know.

However, most APIs that are declared REST APIs by their makers, do not follow the constraint that client-server interaction must be hypertext-driven.(HATEOAS) Often APIs simply return some JSON and does not contain any links to other resources. This tighlty couples client and server because without links clients need knowledge of every endpoint up front and breaks RESTful design.

What REST IS NOT about

What REST IS about

Checklist: Is my API RESTful?

If you recognize these things in your application, there's a high chance, that REST constraints are violated.

For a more comprehensive list, see Roy Fieldings blog.

REST FAQs

Conclusion

The REST architectural style as defined by Roy Fielding defines a set of constraints. A lot of times APIs that are called RESTful violate at least one of them. Most commonly they violate the Uniform interface constraint, because resources are not discoverable due to lacking links in responses.

Hopefully, this page has clarified what REST is and what it isn't. While reading, you may have detected a so-called REST API at work or another place, that actually should not be called one. If you did please:

  1. Stop calling it a REST API.😉. This would make Roy Fielding happy as well.
  2. Kindly, pass on this knowledge or the link to this website to other people, who you feel might benefit from learning what REST is truly about. 🙏

Further Reading

Some links to some excellent resources, which all do a good job explaining what REST is about, and what it isn't about.