How do i can specify @RepositoryRestResource enpoints to response only if mime-type is application/json?
example with @RequestMapping
GET-Request with Accept : application/json returns json
@RequestMapping(path="/path", headers ="Accept=application/json")
public String withHeader() {
return "{this:json}";
}
GET-Request without Accept : application/json header returns html
@RequestMapping("/path" )
public String withoutHeader() {
return "<html>...</html>";
}
You cannot make it out of the box. You need add a configuration like this
@Configuration
class RestMvcConfiguration {
@Bean
public RepositoryRestConfigurer repositoryRestConfigurer() {
return new RepositoryRestConfigurerAdapter() {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.returnBodyOnUpdate("Accept=application/json")
config.returnBodyOnCreate("Accept=application/json");
}
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With