Feign get request with body

Viewed 11882

For some reason I need to call a GET method API and pass json request body for it. I really couldn't find an example for it. I wonder if it is even supported using feign. How can I do that using feign?

2 Answers

Yes, Feign supports it. You can do the same as with POST requests:

@FeignClient(name = "clientName", url = "http://localhost:8888")
public interface SampleFeignClient {

    @GetMapping("/remote")
    String test(@RequestBody SampleRequestBody sampleRequestBody);
}

But be aware: a lot of servers ignore body or even refuse that kind of "non-standard" requests completely (GET or HEAD with request bodies).

According to the documentation the correct way to do it would be to use the @SpringQueryMap annotation.

@FeignClient(name = "clientName", url = "http://localhost:8888")
public interface SampleFeignClient {

    @GetMapping("/remote")
    String test(@SpringQueryMap SampleRequestBody sampleRequestBody);
}

You can find more information here

Related