eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

1. Overview

Web APIs have rapidly evolved with the rise of REST (Representational State Transfer). REST-based APIs allow developers to build powerful web applications that are modular, scalar, and loosely coupled. While RESTful APIs provide a solid foundation, they often lack the essential elements of discoverability and usability.

This is where HATEOAS (Hypermedia as the Engine of Application State) and HAL (Hypertext Application Language) can make a significant difference. Without HATEOAS, RESTful APIs become tightly coupled to the server, requiring hard-coded endpoints on the client side.

In this tutorial, we’ll explore the concepts of HATEOAS and HAL, their relationship, and their key differences.

2. Understanding HATEOAS

HATEOAS stands for Hypermedia as the Engine of Application State. To delve deeper into this concept, we first need to understand the meaning of Hypermedia. Hypermedia is an extension of hypertext that includes text links and other media types, such as images, audio, and video. It allows for rich interactions by enabling users to navigate related resources seamlessly.

HATEOAS enhances API interactions by embedding hypermedia links in responses. This enables clients to navigate and interact with resources dynamically without requiring prior knowledge of the API’s structure. It promotes loose coupling and allows APIs to evolve independently over time.

It means that client-server interactions should rely entirely on hypermedia received in the server’s responses. Each response from the server includes links that guide the client in discovering additional actions and resources along with the data.

Let’s understand more about HATEOAS with the help of a shopping cart example:

When a client requests details about a shopping cart with items, the server provides relevant links for possible actions:

GET /cart/12345 HTTP/1.1

HTTP/1.1 200 OK
{
  "cartId": 12345,
  "items": [
    {
      "id": 001,
      "name": "TV",
      "qty": 1,
      "amount": 4750
    }
  ],
  "totalAmount": 4750,
  "links": [
    {
      "rel": "self",
      "href": "/cart/12345"
    },
    {
      "rel": "addItem",
      "href": "/cart/12345/add"
    },
    {
      "rel": "removeItem",
      "href": "/cart/12345/remove"
    },
    {
      "rel": "checkout",
      "href": "/cart/12345/checkout"
    },
    {
      "rel": "clear",
      "href": "/cart/12345/clear"
    }
  ]
}

In the above example, the client can add or remove more items, proceed to checkout, or clear the cart. All these operations are based on the items available in the cart. The links key indicates the available operations.  Now, let’s consider an example of an empty shopping cart:

GET /cart/987 HTTP/1.1

HTTP/1.1 200 OK
{
  "cartId": 987,
  "items": [],
  "totalAmount": 0.0,
  "links": [
    {
      "rel": "self",
      "href": "/cart/987"
    },
    {
      "rel": "addItem",
      "href": "/cart/987/add"
    },
    {
      "rel": "checkout",
      "href": "/cart/987/checkout"
    },
  ]
}

Now, the client’s available actions are limited. Clients can add items to the cart or proceed to checkout, but they can’t clear or remove items since the cart is already empty. This hypertext tells us what is allowed and what is not.

3. Understanding HAL

HAL is a simple format that helps developers create hypermedia representations for RESTful APIs, supporting the HATEOAS principle. It defines a simple format that gives an easy, consistent way to hyperlink between resources in REST API.

Let’s take a look at the key concepts of HAL.

HAL enables the inclusion of hypermedia links within the resource representation. The _links property lists links related to the resource. Each link includes a rel (relationship type) and a href that clients can use to interact with the API. The _links property also contains a self-link, which allows clients to access the current resource directly.

3.2. Embedded Resources

As the name suggests, embedded resources indicate that other resources are contained within a given REST resource. The _embedded property can hold related resources. This allows the client to access related information without making any additional requests.

3.3. State

HAL uses JSON or XML to encode the resource data and the associated links.

Now, let’s take a look at an example without HAL where the response from an API will look like this:

{
  "cartId": 12345,
  "items": [
    {
      "id": 001,
      "name": "TV",
      "qty": 1,
      "amount": 4750
    }
  ]
}

The above example doesn’t provide any links to related resources. Now, we’ll add HAL links to the response to make it a HAL-compliant example:

{
  "_embedded": {
    "items": [
      {
        "id": 001,
        "name": "TV",
        "qty": 1,
        "amount": 4750,
        "_links": {
          "self": { "href": "/items/001" },
          "update": { "href": "/items/001/update" }
        }
      }
    ] 
  },
  {
    "_links": {
      "self": { "href": "/carts/12345" },
      "addItem": { "href": "/cart/12345/item" },
      "checkout": { "href": "/cart/12345/checkout" }
    }
  }
}

In the above example, the main data is under the _embedded property. Here, the main data contains the list of items in the cart, with each item having its own _links.

4. Relationship Between HATEOAS and HAL

HATEOAS and HAL are closely related concepts in terms of RESTful API design. HATEOAS is a principle of REST that encourages using hypermedia links to let clients explore APIs dynamically. On the other hand, HAL is a specific format that helps implement this by standardizing how to represent resources and their connections via links.

Let’s take a look at the shopping cart example discussed earlier. When a client requests details about a shopping cart with items, the server responds with a HAL representation:

GET /cart/12345 HTTP 1.1

HTTP/1.1 200 OK

{
  "cartId": 12345,
  "items": [{
      "id": 001,
      "name": "TV",
      "qty": 1,
      "amount": 4500
    }],
  "totalAmount": 4500,
  "_links": {
      "self": { "href": "/cart/12345", "rel": "self" },
      "addItem": { "href": "/cart/12345/add", "rel": "addItem"},
      "checkout": { "href": "/cart/12345/checkout", "rel": "checkout" },
      "clear": { "href": "/cart/12345/clear" , "rel": "clearCart" }
  },
  "_embedded": {
      "offer": {
        "code": "DISCOUNT10",
        "discount": 10
      }
  }

In the above example, the _links section provides hypermedia links describing actions the client can take based on the current resource’s state. The rel field is critical because it defines the action that the link represents (e.g. self, addItem, checkout, etc). It’s used to describe the meaning of the link and how the client should interpret it in the context of the API’s state.

 The _embedded section contains related resources embedded directly within the main resource. It allows clients to access related data without making additional requests, reducing network calls and enhancing efficiency.

The resource’s state is captured in the actual data returned in the response, such as items and the total amount of the cart.

5. Key Differences Between HATEOAS and HAL

Let’s take a look at the key differences between HATEOAS and HAL:

Aspect HATEOAS HAL
Concept/Format HATEOAS is a REST architectural principle that guides clients to discover available actions by following server-provided hypermedia links. HAL is a specific format used to represent resources in a way that supports HATEOAS.
Purpose HATEOAS’s purpose is to make APIs self-explanatory and easy to navigate. It reduces the need for clients to have prior knowledge of the API’s structure. HAL provides a clear and concise way to represent resources and their connections. It simplifies parsing and understanding links for clients.
Implementation Various formats and technologies, such as JSON, XML, or even HAL itself, can implement HATEOAS. HAL specifically structures resource representations using JSON or XML, emphasizing links.

6. Conclusion

In this article, we discussed HATEOAS and HAL. While HATEOAS outlines a principle for how a RESTful API should function, HAL provides a concrete implementation that simplifies hypermedia controls in APIs. Using HAL, developers can easily create HATEOAS-compliant APIs, which simplifies resource discovery and interaction for clients.

By combining HATEOAS and HAL, APIs become self-descriptive and discoverable. This results in better decoupling between clients and servers, allowing API to evolve independently over time.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=REST)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)