Introduction To HATEOAS
Posted By : Satyam Goel | 01-Feb-2021
HATEOAS is short for Hypermedia as the Engine of Application State.
- It is a component of the REST application architecture that distinguishes it from other network application architectures. "Hypermedia" is a term referring to any content that contains links to other forms of media such as images, movies, and text.
-
It facilitates easy creation of REST representations by some APIs that follow the HATEOAS principle when working with Spring and especially Spring MVC.
-
In REST architectural style we can use the hypermedia links in the response contents. It means by traversing the hypermedia links, the client can dynamically navigate to the appropriate resources.
-
Navigating hypermedia links is works on the similar concept of a web user browsing through web pages by clicking the relevant hyperlinks to achieve a final goal.
Let's look at an example. Assuming that we have a REST service that provides different product descriptions; think about some e-commerce websites. If we get a JSON response with a product from that website with the help of HATEOAS, it could look something like this -
Also Read: Improving User Experiences With Progressive Web App
{
"productId": 123
"productName": "Refrigerator",
"description": "The best Refrigerator on the planet."
"links": [{
"rel": "self",
"href": "http://localhost:8080/super-shop/api/products/123"
}, {
"rel": "details",
"href": "http://localhost:8080/super-shop/api/products/123/details"
}, {
"rel": "addToCart",
"href": "http://localhost:8080/super-shop/api/addToCart/123"
}]
}
From above Example, we could see few links added which is an array of list to that JSON. In that particular links we have two fields
1. rel
2. href
1. rel –
It stands for ‘relationship’ and explains how the link relates to the object that we requested for. self
– meaning, this link takes us to the object, details
– means detailed information is available, addToCart
– indicates the process of adding this product to a shopping cart.
2. href –
A complete URL that shows how the action can be performed.
Also Read: Reading a CSV file in java
HATEOAS will reduce the need for configuring URL endpoints which is a great thing. All these URLs telling us how to look up product details? How to add a product to the cart? We don’t need them hardcoded or in some configuration files. They are supplied by the application. If we really want to have something in our config files, we could place the rel
– relationships there. In any application, we have different REST API calls. This makes it a real benefit of sorts.
Why You Should Choose Oodles For SaaS Product Development?
We are a 360-degree software development company that provides cross-platform SaaS app development services to address varied software project requirements. We have an experienced team of Java, PHP, and Python developers who use advanced frameworks, tools, and SDKs to build scalable web and mobile applications with custom features. For more detail, reach us out at [email protected].
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Satyam Goel
Satyam Goel is an experienced backend developer with expertise in Java technology. He possesses a solid understanding and practical knowledge of Core Java, Spring-Boot, Hibernate, JUnit, and relational databases like MySQL, PostgreSQL, and more. Satyam is proficient in API implementations, web services, development testing, deployment, and code enhancements. His contributions to various client projects, such as SEI, Herdsy, Bhaasha, and Ignitiv, based on e-commerce and other domains. Satyam's creative mind and analytical skills have enabled him to deliver high-quality solutions. He also has knowledge of cloud services such as AWS, Google Cloud, and Microsoft Azure, making him a versatile and valuable member of any development team.