bergacat1
bergacat1

Reputation: 133

How to handle the GET method so that I can update the requested object before returning it?

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

Answers (2)

kuhajeyan
kuhajeyan

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

Shem
Shem

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

Related Questions