BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Spring adds HATEOAS Support to REST Based Web Services

by Jan Stenberg on May 21, 2013 |

The Spring Framework for Java is currently in progress of adding HATEOAS, Hypermedia As The Engine Of Application State, support for hyper-text driven REST web services. Primary focus for the library is to provide an API for simplifying the creation of hypermedia links and assembling of REST resource representations when used together with Spring and especially Spring MVC.

XML and JSON
The library provides a set of types to simplify working with both XML and JSON.

Links
Several classes are provided for working with links and relations.
The Link class is used for creating and holding links, using the Atom link definition with a rel and a href attribute for describing a link. When using XML the link representation will be rendered in the Atom namespace.
A common problem when creating URI strings is the spread of duplicate string constants over the code base. The ControllerLinkBuilder class addresses this problem by extracting the base URI from the current request and then adding the root mapping from the Controller class for the corresponding resource to get a complete URI.
When resources are direct representations of model classes, classes are provided for creating links for these model types, pointing to either a collection resource or a single resource.
Finding the link corresponding to a given relation is a common task when using hypermedia. Support for this is provided through a LinkDiscoverer class.

Resources
When creating resource classes, the library contains a base class, ResourceSupport, to inherit from, e.g. for links support.
Another base class, ResourceAssemblerSupport, helps reducing the amount of code needed for mapping between entities and resources and for adding links to a resource. This assembler class is furthermore capable of creating a single resource or a collection of resources.

Geraint Jones has written an example with a simple scenario using the library.

At JAX 2013 Martin Lippert held a presentation “Modern Architectures with Spring and JavaScript” which includes the library.

The Spring HATEOAS Library is currently in Release 0.5 with work in progress for 0.6.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT