Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring HATEOAS & HAL: Can I serve just Links but no content?

What it says in the title.

I want to serve a root resource that consists only of links to the "lower" resources. It seems that Resource as well as HttpEntity want an object with some content as their type, so how can I serve just Links?

Thanks.

like image 217
Kirby Avatar asked Mar 03 '15 16:03

Kirby


People also ask

What is spring HATEOAS?

The Spring HATEOAS project is a library of APIs that we can use to easily create REST representations that follow the principle of HATEOAS (Hypertext as the Engine of Application State).

Should I use spring HATEOAS?

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.

Why do we need spring HATEOAS?

Spring HATEOAS provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and especially Spring MVC. The core problem it tries to address is link creation and representation assembly.

What is HATEOAS in Java?

HATEOAS acronyms for Hypermedia as the Engine of Application State. The term hypermedia refers to content that contains a link to other forms of media like images, movies, and text. It is a component of the REST application that distinguishes it from other network architecture.


1 Answers

So what you conceptually do is returning an empty collection resource with links attached. This can be achieved by this snippet of code:

List<Link> links = …
return new Resources<Object>(Collections.emptySet(), links);
like image 155
Oliver Drotbohm Avatar answered Sep 27 '22 16:09

Oliver Drotbohm