I am having below a controller(just for example) method:
@Autowired
EntityLinks entityLinks;
@GetMapping(value = "{userId}", params = "sortBy")
public Resource<User> getUser(@PathVariable Integer userId, @RequestParam String sortBy ){
Resource<User> userResource = new Resource<>(new User());
userResource.add(entityLinks.linkToSingleResource(getClass(), userId));
return userResource;
}
GET http://localhost:8085/api/v1/test/11?sortBy
returns me:
{
"name": null,
"email": null,
"_links": {
"self": {
"href": "http://localhost:8085/api/v1/test/11"
}
}
}
My concern is, from "href": "http://localhost:8085/api/v1/test/11"
how could any client(or the person using the API) would guess if sortBy
query param is required by the API? And what values sortBy
demands e.g id
,name
Is there any way to generate more helpfull href
? e.g "href": "http://localhost:8085/api/v1/test/11{?sortBy=id,name}"
. Means sortBy
can only accepts id
and name