Java Reference
In-Depth Information
Link.valueOf(response.data.links.self).uri ==
'http://localhost:1234/people/3'.toURI()
Link.valueOf(response.data.links.next).uri ==
'http://localhost:1234/people/4'.toURI()
}
The response body now has a links element, which contains prev , self , and next as
child elements.
Lessons learned (hypermedia)
1. JAX-RS mostly ignores hypermedia but does make some methods available for it.
2. Transitional link headers are added by the link and links methods in
Response-Builder .
3. Structural links in the body are added through a special JAXB annotation.
4. You can manage the parsing and response generation stages yourself by writing
a provider class that implements MessageBodyReader and/or Message-
BodyWriter .
Betweenthetransitionallinks,thestructurallinkswiththeJAXBserializer,andtheGroovy
JsonBuilder , hopefully you now have enough mechanisms to implement hypermedia
links in any way your application requires. The choice of which to use is largely a matter
of style, but there are some guidelines:
• Structural links are contained in the response, so the client has to parse the re-
sponse to get them.
• Transitional links are in the HTTP headers. That gets them out of the response but
forces the client to parse the HTTP response headers to retrieve them.
• Custom links can be anything, so they must be clearly documented.
Examples of all three approaches can be found on the web.
9.6. Other Groovy approaches
There are three other approaches in the Groovy ecosystem that I should mention for REST-
ful web services. Here I'll specifically discuss groovlets, the Ratpack project, and Grails.
Search WWH ::




Custom Search