0

I am looking to develop a Spring MVC Integration with HATEOAS. I've searched the web and I didn't find any such working example through which I can understand HATEOAS concept.

I only found this resource which itself has lots of code and is really difficult to understand. Is a complete working sample available?

halfer
  • 19,824
  • 17
  • 99
  • 186
PAA
  • 1
  • 46
  • 174
  • 282
  • Have you looked into spring-data-rest? Git: https://github.com/spring-projects/spring-data-rest. Guide http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/ – Anton N Apr 15 '15 at 19:16
  • Example https://spring.io/guides/gs/accessing-data-rest/. Or https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-rest – Anton N Apr 15 '15 at 19:18

3 Answers3

0

There's a pretty basic example in this repository. A more advanced showcase can be found in Spring RESTBucks.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
0

Here's sample EchoService described step-by-step with explanations in code. It is using Spring Boot HATEOAS and shows sample Spock test with TestRestTemplate.

HATEOAS means (at least in my mind :-) ) that you treat a HTTP resource as a state machine, which means that it can change depending on its (system) internal state.

The most common example is a bank account as a resource. Accessing the resource (account) returns various informations about it and links to operations that can be performed on it. And those operations (hence available links) depend on the account's state. If a user has money then the links could be { "deposit": "deposit-url", "withdraw": "withdraw-url" }. When a user has no money on the account, then the returned links (available actions) could be { "deposit": "deposit-url" }. So the list of available operations/actions/links varies and depends on resource's state.

Another common example is having different menu items depending on user's role/permissions. In apps, which generate whole page on server side, you could generate links to different actions in page template by simple checks: if (isAdmin(currentUser)) { {generate secret link} } else { ... }. But when using REST services most clients are JavaScript apps, where you can't do any permissions checks. So here HATEOAS helps by returning menu actions (links) depending on user's role/permission on server side and REST client doesn't have to worry about it.

halfer
  • 19,824
  • 17
  • 99
  • 186
pwojnowski
  • 382
  • 4
  • 8
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – NathanOliver May 27 '15 at 18:15
0

You may have a look at this sample Spring/Boot HATEOAS project: https://github.com/opencredo/spring-hateoas-sample and some explanation in the related blog post: Implementing HAL hypermedia REST API using Spring HATEOAS

The examples shows a simple but not-so-trivial API.

The API represents a fictional library with a catalogue of books, related with authors and publishers.

All Resources includes examples of links. Book GET also also shows how to return different level of details, either embedding or linking related resources.

Beyond GET examples for all resources, it also includes other "command" endpoints, like for adding a book to the collection, borrowing and returning books.

Nicus
  • 86
  • 7