Java Reference
In-Depth Information
20
Believe it or not, neither the words hypermedia nor HATEOAS
appears at all
in the JSR 339 specification. I have
no explanation for this.
• Transitional links in HTTP headers
• Structural links embedded in the response
Figure 9.4
shows both in a single HTTP response.
Figure 9.4. Transitional links appear in the HTTP response headers, while structural links are part of the response
objects. In each case the links can be used to access other resources from this one.
Version 2.0 of the JAX-RS specification supports transitional links using the
Link
and
LinkBuilder
classes, and structural links using a special JAXB serializer.
To illustrate both, I'll continue with the
Person
example from earlier by adding links to
each instance. Each person has three possible links:
• A
self
link, containing the URL for that person
• A
prev
link, pointing to the person with an ID one less than the current person
• A
next
link, pointing to the person with an ID one greater than the current person
This is a rather contrived case, but it has the advantage of simplicity.