What is HATEOAS?

The term HATEOAS is abbreviated as "Hypermedia as the Engine of Application State" is an attribute of REST limiting its application construction so that your way of designing RESTful architecture seems unique from all other architecture of different network apps. HATEOAS provides a connection through hypermedia.



The phrase "hypermedia" can be defined as any content which holds connections for various other types of media like images, text, video clips as well as movies. REST provides an architectural approach that will allow you to use hypermedia links on those media contents so that your clients can navigate to all suitable resources at runtime as they traverse through these hypermedia links. The concept is the same for web page navigation through exact hyperlinks for reaching the desired resources.

Here's an example, where using JSON response, API like with HTTP GET can be formed:

http://api.domain_name.com/manage/designations/20

{
  "designationID": 20,
  "designationName": "Tech-writer",
  "location": 346,
  "managerID": 180,
  "links": [
    {
      "href": "/demoApp/employees/20",
      "rel": "employees",
      "type": "GET"
    }
  ]
}

From the previous example, the server holding response to hypermedia links concerning employee-designation resources for 20/employees can be traversed easily by the client. It also increases the readability of navigating in which employees belong to that department. This approach is beneficial because the links in this hypermedia are coming back from the server, compel the application's position.

Another Representation

A straightforward means to provide as many connected links as probable regarding the source is using the response. Here is a case of registration application for a new employee in an organization.

The usual response of the employee details will have a path: /demoApp/employees/06:

{
   "id": "10",
   "fName": "Dennis",
   "lName": "Ritchie",
   "age": "46"
}

In case you provide any extra information to the client, let suppose, for which job profile that person is getting hired or enrolled into, then the additional link will be something like this:

{
   "id": "10",
   "fName": "Dennis",
   "lName": "Ritchie",
   "age": "46",
   "link": {
      "rel": "designation",
      "href": "/demoApp/employees/6/designations"
   }
}

This structure becomes useful for the client as anyone can straightforwardly get the details about the job profile for which the hiring is being done and a direct path following the resource URI information that is from the employee's response. This is possible because of the HATEAOS concept.

So HATEOAS is a perception or model for providing links of the associated sub-resources for the main resource requested by any client, which becomes easier to construct added calls to your REST API.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram