Reputation: 133
I'm working with an API implemented with Spring Data Rest and I would need to handle the GET method like I can do with the @RepositoryEventHandler
, which allows me to handle before/after save, create, delete...
The case is that I need to update the object to be returned gathering information from other APIs before returning it as the GET response.
Is there any way to handle the GET in spring data rest?
Upvotes: 1
Views: 222
Reputation: 11077
you could add Interceptor implementing HandleInterceptor and add it to mapped inteceptor bean.
@Bean
public MappedInterceptor myMappedInterceptor() {
return new MappedInterceptor(new String[]{"/**"}, new MyInterceptor());
}
Upvotes: 1
Reputation: 565
You probably need to use @RepositoryRestController for this. It lets you get stuff from the @Repository and then add new things to the response object. Pretty similar to @RestController, but keeps Spring Data REST’s settings, message converters, exception handling, and more.
Upvotes: 2