Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...