Java Reference
In-Depth Information
I'll demonstrate the hypermedia capability by walking through the links one by one in a
client. The following listing is a JUnit test case, written in Groovy, that accesses the
next
links.
Listing 9.8. Walking through the data using link headers
The client uses the
getLink
method with the relation type (
next
or
prev
), which re-
turns a
Link
instance. The
getUri
method then returns an instance of
java.net.URI
,
which can be followed by the client on the next iteration.
[
21
]
21
I have to mention that this is probably one of the only times in the last decade that I really could have used a
do
/
while
loop. Ironically, that's just about the only Java construct not supported by Groovy.
If you would rather put the links in the body of the response, you need a different approach,
as described in the next section.