I use Spring Data REST with spring.data.rest.base-path property set as /api. If I extend CrudRepository for User entity, I'll have an /api/users endpoint available in my RESTful service. Now assume, I want to add a custom endpoint to /api/users like this:
@RepositoryRestController
public class UserController {
@PatchMapping(path = "/users/{username}/update", produces = "application/hal+json")
@ResponseStatus(HttpStatus.OK)
public EntityModel<User> updateUser(@PathVariable String username, @RequestBody User user) {
// some update logic here ...
return EntityModel.of(user);
}
}
The path element in @PatchMapping annotation still contains explicit hardcoded /users part in it. Is there any programmatic way to replace it with the path variable to the collection resource of User type which is managed by Spring Data REST?