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

2

6

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.

Munshi answered 3/3, 2015 at 16:57 Comment(0)
C
7

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);
Clarkia answered 9/3, 2015 at 11:44 Comment(0)
I
0

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")));
Interactive answered 29/1, 2023 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.