Spring Mvc and MediaType for consumes in @RequestMapping for a get rest request
11,769
According to the documentation, consumes
has to match the value of Content-Type
header so the value you need to send for the mapping depends on what the client sets in the header.
Related videos on Youtube
Comments
-
JeanValjean over 1 year
I'm implementing a REST application using Spring Boot. I want to specify the
consumes
parameter for the@RequestMapping
annotation. The rest call should be something like:http: // mysite.com/resource/123
In the controller I handle this as follows:
@RequestMapping(value = "/resource/{id}", method = RequestMethod.GET, consumes = XXX, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Scenario getResource(@PathVariable("id") final long id) { //... }
The default value, i.e. all, is obvious and not specific. So, which should be the correct
MediaType
forconsumes
? -
JeanValjean over 8 yearsWhat about the example with the id? Which would be the correct MediaType?
-
jny over 8 yearsWhat are you trying to achieve? Are you askig what is the right way from the REST point of view?
-
JeanValjean over 8 yearsYes, exactly. Any idea?