17 Tweets Jan 31, 2023
Most of the REST APIs we use are not actually REST APIs.
They are REST-Like.
A thread on what makes your API purely REST. ๐Ÿงต
REpresentational State Transfer is the widely used API architecture in use nowadays.
It was originally founded by Roy Fielding in Ph.D. dissertation.
๐Ÿ”— ics.uci.edu
On a broader note, REST API follows six architectural constraints.
โ€ข Client-server Separation
โ€ข Stateless
โ€ข Cacheable
โ€ข Layered System
โ€ข Uniform Interface
โ€ข Code on Demand (optional)
Read more about these in this thread:
Among all the constraints mentioned above, uniform interface emphasizes REST to make it different from other API architectures and styles.
And in fact, a uniform interface is something that makes API REST and REST-Like.
Let's try to understand it first. ๐Ÿ‘‡๐Ÿป
The Uniform interface is a pretty intuitive term.
Uniform means consistent
Interface means what the client sees.
The uniform interface defines the interface between client and server, aiming for simplified and decoupled architecture.
In simple terms, intuitive and easy to use API.
Uniform Interface is further divided into four parts.
โ€ข Identification of resources
โ€ข Manipulation of resources through representations
โ€ข Self-descriptive messages
โ€ข Hypermedia as the engine of application state (HATEOAS)
The fourth point, HATEOAS is something that makes your API REST-Like or REST.
Let's discuss all four points first ๐Ÿ‘‡๐Ÿป
๐Ÿ“Œ Identification of resources
Identification of resources can be done by URI and its naming.
๐Ÿ“Œ Manipulation of resources through representations
We have PUT, PATCH, and DELETE HTTP methods using which we can manipulate the state of resources.
๐Ÿ“Œ Self-descriptive messages
Every returned resource should be descriptive so that client can use it efficiently.
This can be achieved by using the `Content-Type` header which indicates the content type of returned resource.
๐Ÿ“Œ HATEOAS
This is the most crucial point of this thread and HATEOAS decides whether an API is REST or REST-Like.
HATEOAS stands for Hypermedia As The Engine Of Application State.
Before understanding HATEOAS, we need to learn what is hypermedia.
Hypermedia is nothing but the extension of hypertext that links to different media (image, audio, video, text), especially within an API.
HATEOAS defines that clients should be provided with hypermedia, in response to a particular request, which help them to use or explore further points of an API.
For example ๐Ÿ‘‡๐Ÿป
So if we look deeper into it, we will find that almost every REST API follows:
โ€ข Identification of resources
โ€ข Manipulation of resources through representations
โ€ข Self-descriptive messages
But HATEOAS is something that we do not find in all the APIs.
HATEOAS is not very much hard to implement.
Make sure to implement in your API to deliver pure REST APIs.
With that said, this is the end of this thread.
Follow @Rapid_API for more exclusive content about APIs. ๐Ÿ™๐Ÿš€

Loading suggestions...