Spring HATEOAS versus Spring Data Rest

HighTML picture HighTML · Oct 22, 2013 · Viewed 17.8k times · Source

Question is, what's the difference between Spring HATEOAS versus Spring Data Rest ?

I feel both can do the same, and Spring Data Rest (as part of Spring Data) seems a bit more alive.

https://github.com/spring-projects/spring-hateoas https://github.com/spring-projects/spring-data-rest

When would you use one or the other?

Answer

Oliver Drotbohm picture Oliver Drotbohm · Oct 22, 2013

Spring HATEOAS provides common abstractions (representational models, a Link class, API to build links pointing to Spring MVC controllers, etc.) to ease building hypermedia driven REST APIs with Spring MVC in general. Thus, you can use it alongside Spring MVC to manually build those services.

Spring Data REST uses Spring HATEOAS to automatically expose resources for entities managed by Spring Data repositories and leverages hypermedia aspects to do pagination, link entities etc. So it covers the 80% use case for the basic stuff and allows you to selectively add more complex processes using manually implemented controllers later on.

To get a feel for this, feel free to have a look at the Spring RESTBucks sample project. The handling of Order instances is completely done by Spring Data REST (with some minor tweaks to implement business constraints). The entire payment logic is then implemented manually as the process does not fall into the CRUD category as we actually need to implement certain steps and a protocol to complete the order. Again, the code is here, a slide deck with some additional visuals can be found at speakerdeck.com.