I have a spring data repository like that:
@RepositoryRestResource(collectionResourceRel = "items", path = "items")
public interface ItemRepository extends CrudRepository<Item, Long> {
}
and my custom repository:
@RepositoryRestController
@ExposesResourceFor(Item.class)
@RequestMapping("items")
public class CustomItemController implements ResourceProcessor<RepositoryLinksResource> {
@Autowired
ItemRepository itemRepository;
@GetMapping(value = "/customMethod")
@ResponseBody
public List<String> customMethod() {
//some logic
}
@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
resource.add(linkTo(methodOn(CustomItemController.class).customMethod()).withRel("customMethod"));
return resource;
}
}
I would like to have a link to the custom method on the level of collection entities,
{
_embedded: {
items: [...]
},
_links: {
self: {
href: "https://localhost:8080/api/items"
},
profile: {
href: "https://localhost:8080/api/profile/items"
},
search: {
href: "https://localhost:8080/api/items/search"
},
customMethod: {
href: "https://localhost:8080/api/items/customMethod"
}
}
}
but with the above solution I have it at the root level of my API. If I change RepositoryLinksResource to the Resource, I will have the method on the level of entity. Any ideas/clues how to implement it?