Kirby
Kirby

Reputation: 413

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.

Upvotes: 6

Views: 1417

Answers (2)

Ameen Demidem
Ameen Demidem

Reputation: 19

I couldn't figure out which "Resources" that was and I wanted to return a proper HAL representation in order to make use of "/" as the entry point in HAL Explorer. This worked out for me:

return ResponseEntity.ok(new RepresentationModel<>()
    .add(linkTo(methodOn(SomeController.class).GET()).withRel("some-rel")));

Upvotes: 0

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83061

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);

Upvotes: 7

Related Questions