BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Spring adds HATEOAS Support to REST Based Web Services

| by Jan Stenberg on May 21, 2013. Estimated reading time: 1 minute |

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.

Rate this Article

Adoption Stage
Style

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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT