It is fairly common to expose the following endpoints for REST resources
@GET customers/ ==> list of customers
@POST customers/ ==> add a customer
@Get customers/:id ==> specific info of customer
@PUT customers/:id ==> override a customer
@PATCH customers/:id ==> update customer
Spring data rest repository handles this very well.
But if I'd like to add custom end points like
@GET customers/recent ==> retrieve customers recently visited @GET customers/:id/photo ===> all photos belonging to that customer
Is there a way to add to the existing set of endpoints?
Of course, we can repeat all the idiomic code in a @RestController
annotated class, but that would be very repetitive for 10+ resources.
What I am looking for is like this
class CustomerController{
// all @GET, @POST, @PUT, @PATCH methods are already generated, like a data rest repository
@RequestMapping(value = "/{customerId}/photo", method = RequestMethod.GET)
public Collection<Photo> getAllPhotos(){
...
}
// it is also possible to override @POST request here
public Collection<Customer> getCustomers(){
// more logic
}
}