From the course: Java EE: RESTful Service with JAX-RS 2.0

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

HATEOAS and JAX-RS

HATEOAS and JAX-RS

From the course: Java EE: RESTful Service with JAX-RS 2.0

Start my 1-month free trial

HATEOAS and JAX-RS

- [Instructor] Okay, so how do we implement HATEOAS and JAX-RS? Well, there are two ways. The first way is to do exactly what I've explained before, which is to add those links to the resource, itself. But there is an alternative way to communicate those links to the client. And that is to add them to the HTTP header of the response. This is actually the easiest way to HATEOAS enable your API. So, let's look at how to do this. So, in both cases, the code that adds the links to the resource is located in the entity resource class, in the method that actually responds to the request. So, JAX-RS provides a nice build to API that constructs links to resources called link. So, from the link class, call the from URI method and pass it a reference to the base URI. This is obtained by injecting the current request context URI info and from this we call the get base URI builder method. From here, we call the path method and pass it the current class. This reads the path URI for the current…

Contents