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?
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
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