I'm mapping all my api endpoints under the base url /api/
. Now I want to expose all the available endpoints by using spring-data-rest via HATEOAS so that a client application can process these information. By default this seems to work out of the box, as a GET /api/
returns all found Spring repositories and their respective url like this:
{
"_links" : {
"news" : {
"href" : "http://localhost:8080/api/news{?page,size,sort,projection}",
"templated" : true
}
}
}
However, I would like to add some custom links to other resources. I tried this:
@RequestMapping("/api")
public class AppController {
@RequestMapping("/")
public ResponseEntity<ResourceSupport> getEndpoints () {
ResourceSupport resource = new ResourceSupport();
resource.add(linkTo(UserController.class).withRel("users"));
return new ResponseEntity<>(resource, HttpStatus.OK);
}
}
But this actually overwrites everything. So my question is how can I extend the standard output of spring-data-rest for the base resource with some custom links?