HATEOAS and Why It’s Needed in RESTful API?
Last Updated :
02 Oct, 2022
HATEOAS stands for Hypermedia as the Engine of Application State and it is a component of RESTful API architecture and design. With the use of HATEOAS, the client-side needs minimal knowledge about how to interact with a server. This is made possible by the network application responding to the client’s requests with dynamically generated information through the use of hypermedia.

When accessing a webpage through a browser, users have the ability to interact with the webpage by using buttons, inputs, clicking on links, etc. However, traditional API responses have no such functionality present to allow an application to interact with the server through the response. HATEOAS acts as a way to address this. A HATEOAS request allows you to not only send the data but also specify the related actions.
Application State Change Through HATEOAS
When using HATEOAS architecture, a client will be able to access the API for a network application through a simple, static, RESTful URL call. Now, any further actions, that the client may wish to take, will be enabled by the data, returned by the server, in the original call. This will enable the client to move from one application state to the next just by interacting with the details contained in the responses by the server.
The “data”, within the response, that enables this change of state is simple hypermedia links. This is how HATEOAS manages the change in application states through hypermedia.
Demonstration of the Use of HATEOAS
As an example, consider that a client wants to interact with a network application to fetch details of employees’ payroll within an organization. The RESTful call to enable this would be as follows:
GET /payroll/employee_123 HTTP/1.1
The server will respond with a JSON containing the required details. Additionally, the response will contain hypermedia links that allow the client to take further actions. As an example, consider the response by the server is as follows.
HTTP/1.1 200 OK
Content-Type: application/+json
Content-Length: ...
{
"payroll": {
"employee_number": "employee_123",
"salary" : 1000,
"links": {
"increment": "/payroll/employee_123/increment",
"decrement": "/payroll/employee_123/decrement",
"close": "/payroll/employee_123/close"
}
}
}
We can observe that, in addition to the expected information being received in the response, additional information is presented in the form of RESTful hypermedia calls under the “links” title. These links allow further interaction with the server by incrementing or decrementing the salary or closing the account. It may be noted that these links correspond to the respective API endpoints to increment, decrement, and close the payroll account. Also, these links are pre-populated with the employee identifier. This means that such content is dynamically generated.
An additional example of how these hypermedia links are dynamically generated can be demonstrated is as follows:
Assume that for a given employee, the account has been closed. Thus, the increment and decrement methods are irrelevant to such an account. Thus, hitting the payroll endpoint for such an employee would result in response as follows:
HTTP/1.1 200 OK
Content-Type: application/+json
Content-Length: ...
{
"payroll": {
"employee_number": "employee_123"
"links": {
"start": "/payroll/employee_123/start"
}
}
}
In this case, the links have changed to include functions that are relevant to the current state only. Thus, the only action made available is to “start” the payroll for such an employee.
Need for HATEOAS
With traditional, non-HATEOAS based API systems, the API endpoints need to be hard-coded within the client-side application. Any changes to this endpoint would result in the client application systems breaking down. Thus, such changes would need to be updated in each of the client’s applications. This system is, therefore, tightly coupled.
With HATEOAS, the system becomes loosely coupled as the URLs do not require hard-coding. Instead, the URLs are generated on the fly on the server-side and supplied to the client through the JSON responses. Clients can now use these URLs from the response and be sure that these URLs are the latest versions.
Similar Reads
What Makes an API RESTful?
In web development, APIs help different software systems to interact with each other. They allow applications to request data or services from other programs, making it possible for developers to create complex, integrated systems. One common style for designing APIs is REST (Representational State
6 min read
Difference Between REST API and RESTful API
Both REST API and RESTful API are often used interchangeably in the software development community, but there are subtle differences between the two. Understanding these differences is important for building modern web applications, as both have significant roles in enabling communication between cl
7 min read
Difference between REST API and SOAP API
REST (Representational State Transfer) and SOAP (Simple Object Access Protocol) are the most common methods for communications. These services enable the web to communicate with the servers with HTTP protocol. REST is an architectural style that works over HTTP for communication, while SOAP is a pro
2 min read
What is Web API and why we use it ?
API stands for Application Programming Interface. API is actually some kind of interface which is having a set of functions. These set of functions will allow programmers to acquire some specific features or the data of an application. Web API is an API as the name suggests, it can be accessed over
5 min read
What is REST API in Node.js ?
NodeJS is an ideal choice for developers who aim to build fast and efficient web applications with RESTful APIs. It is widely adopted in web development due to its non-blocking, event-driven architecture, making it suitable for handling numerous simultaneous requests efficiently. But what makes Node
7 min read
Using Restify to Create a Simple API in Node.js
Restify is an npm package that is used to create efficient and scalable RESTful APIs in Nodejs. The process of creating APIs using Restify is super simple. Building a RESTful API is a common requirement for many web applications. Restify is a popular Node.js framework that makes it easy to create RE
6 min read
Difference Between REST API and RPC API
REST and RPC are design architectures widely used in web development to build APIs (Application Programming Interface). It is a set of instructions that permits two systems to share resources and services. The client creates a request to the server that responds to it with data in JSON or XML format
3 min read
What is an API Header?
An API header is part of the HTTP request or response that carries additional information about the request. This information can include metadata such as content type, authentication tokens, and other custom data needed by the server or client to properly process the request or response. API header
5 min read
What is an Idempotent REST API?
Idempotent REST API means that if the same request is made a number of times then it will have the same impact as making the request just once. Lastly, the idempotent characteristic is essential for creating dependable and linear web services when clients might attempt to send the same request multi
7 min read
Why REST API is Important to Learn?
API... Being a developer what comes to your mind first when you listen to this word... JSON, Endpoints, Postman, CRUD, Curl, HTTP, Status Code, Request, Response, Authentication, or something else... If you're familiar with the above word then surely you might have worked on some kinds of APIs (espe
8 min read