Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign get request with body

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?

like image 579
Ali Farhoudi Avatar asked Jun 15 '26 15:06

Ali Farhoudi


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).

like image 151
amseager Avatar answered Jun 17 '26 10:06

amseager


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

like image 44
chaitanya guruprasad Avatar answered Jun 17 '26 10:06

chaitanya guruprasad