0

I'm using Spring Boot and Spring MVC and I need to make a GET with a request body. Is this possible?

I tried this but it's not working. I get 404.

@RestController
@RequestMapping("/api")
public class HomeController {

    @GetMapping("/v1/foo")
    public ApiRes postBody(@RequestBody ApiReq apiReq) {
        ...
    }
}
elvis
  • 738
  • 6
  • 23
  • 41
  • 1
    It is possible to do so, but this is against HTTP design guidelines. If you are forced to use GET requests, I would recommend you use query parameters. Otherwise, use a POST request. – Markiian Benovskyi Mar 08 '22 at 10:52
  • https://stackoverflow.com/questions/34956899/does-spring-requestbody-support-the-get-method Please check this out – prabhu gandhi Mar 08 '22 at 10:59

1 Answers1

3

Technically it is possible but it is against the HTTP API Design Guidelines. Request-Bodys should only be used for POST or PUT.

For further information: https://swagger.io/resources/articles/best-practices-in-api-design/