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.

Share:
11,769

Related videos on Youtube

JeanValjean
Author by

JeanValjean

I need pizza!!!

Updated on September 15, 2022

Comments

  • JeanValjean
    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 for consumes?

  • JeanValjean
    JeanValjean over 8 years
    What about the example with the id? Which would be the correct MediaType?
  • jny
    jny over 8 years
    What are you trying to achieve? Are you askig what is the right way from the REST point of view?
  • JeanValjean
    JeanValjean over 8 years
    Yes, exactly. Any idea?