Hypermedia REST API

Hypermedia is nothing but in simple terms it has hyperlinks associated with the API endpoint. It helps the API to link to related resources associated with the endpoint. This reduces the coupling between the server and the client.

A hypermedia-driven REST API, often called a HATEOAS (Hypermedia As The Engine of Application State) API, utilizes hypermedia to enable dynamic interactions between clients and servers. In a hypermedia-driven API, clients navigate the API by following hyperlinks embedded within the responses received from the server, rather than relying on predefined URLs or endpoint structures. 

Let me take an e-commerce online store as an example to explain more.

When I search for a resource namely a product, it associates with its own API endpoint, links to 'Add to Cart', 'Save for Later', 'Buy Now', and 'Similar Products'. These connected links are called  Hypermedia links. I do not need multiple endpoints to refer to other endpoints because it has everything for easy access.

1. Resource Model:

Products: Represents individual products available for sale in the online store.

2. Endpoints:

/products: Endpoint for accessing the collection of products.
/products/{product_id}: Endpoint for accessing a specific product by its unique identifier.

3. Hypermedia Links:

Each product resource includes hypermedia links to related actions or resources. 

For example:
self: Link to the product resource itself.
add_to_cart: Link to add the product to the shopping cart.
save_for_later: Link to save the product for future reference
buy_now: Link to purchase the product immediately
similar_products: Link to discover similar products.

There are multiple hypermedia REST APIs available in the market. It helps to build APIs that embrace hypermedia principles and offer benefits such as flexibility, discoverability, and evolvability of API designs

A few of the Hypermedia-driven REST APIs are:

1) Cortex
2) GitHub API
3) Spring HATEOAS (Hypermedia As The Engine Of Application State)
4) HAL (Hypertext Application Language)
5) JSON API
6) Collection_API
7) Siren
8) JSON LD (JSON for Linking Data)
9) HTML (HyperText Markup Language)

10) ODATA (Open DATA Protocol)

Advantage:

  • With the help of Hypermedia-driven REST APIs, the client can directly access the links provided by the server without spending time constructing new requests.

Drawback:

  • The server needs to make extra effort to construct the links creating and referring the state transitions related to the resource requested by the client.
  • If the client does not use these links provided, all the efforts taken by the server are not useful.

Comments

Popular posts from this blog

How to Install Jenkins

HTTP Payloads

Variables in Postman