Feign HTTP GET Request Body Example
Feign is a declarative HTTP client in the Spring ecosystem that simplifies calling external APIs. While Feign makes it easy to define REST clients, one common issue we face is attempting to send a GET request with a request body, a pattern that is technically allowed by HTTP but not widely supported by servers. In this article, we will explore how to handle this scenario in a Spring Boot application using Feign.
1. Project Setup
We’ll set up a simple Spring Boot project that includes Feign support.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
We include spring-cloud-starter-openfeign for Feign support.
Main Application Class
@SpringBootApplication
@EnableFeignClients
public class FeignGetBodyApplication {
public static void main(String[] args) {
SpringApplication.run(FeignGetBodyApplication.class, args);
}
}
@EnableFeignClients scans for Feign client interfaces in the application. This is required for Spring to generate proxy implementations at runtime.
2. Trying to Send a GET Request With a Body
HTTP/1.1 specification (RFC 7231) technically allows GET requests to contain a body, but many servers and clients ignore or reject it. If we attempt this directly with Feign, we’ll encounter issues.
Example Feign Client (Problematic Approach)
@FeignClient(name = "exampleClient", url = "http://localhost:8080")
public interface ExampleClient {
@GetMapping("/filter")
String filterWithBody(@RequestBody FilterCriteria criteria);
}
class FilterCriteria {
private String category;
private String type;
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Here, we attempt to send a FilterCriteria object in the body of a GET request. When you run this code, Feign throws an exception or the server ignores the request body because GET requests are generally not designed to include one.
To demonstrate this, we’ll create a runner class that triggers the Feign client call.
@Component
public class FeignTestRunner implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(FeignTestRunner.class);
private final ExampleClient exampleClient;
public FeignTestRunner(ExampleClient exampleClient) {
this.exampleClient = exampleClient;
}
@Override
public void run(String... args) {
FilterCriteria criteria = new FilterCriteria();
criteria.setCategory("Books");
criteria.setType("Fiction");
try {
String response = exampleClient.filterWithBody(criteria);
logger.info("Response: {}", response);
} catch (Exception ex) {
logger.error("Error occurred while calling Feign client: {}", ex.getMessage());
}
}
}
When you run the application, Feign will attempt to send a GET request with a request body. Most servers and Feign itself will not support this properly, resulting in an exception similar to the following:
: Error occurred while calling Feign client: [405] during [GET] to [http://localhost:8080/filter]
[{"timestamp":"2025-11-13T18:36:22.481+00:00","status":405,"error":"Method Not Allowed","path":"/filter"}]
The error confirms that the HTTP GET method does not support sending a body with the request.
3. Using @SpringQueryMap to Fix the GET Request
Spring Cloud OpenFeign provides @SpringQueryMap, which maps object properties to query parameters. This approach allows us to simulate sending a “body” for a GET request without breaking HTTP conventions.
Fixed Feign Client
@FeignClient(name = "exampleClient", url = "http://localhost:8080")
public interface ExampleClient {
@GetMapping("/filter")
String filterWithBody(@SpringQueryMap FilterCriteria criteria);
}
Now, calling this client with a FilterCriteria object like:
@Override
public void run(String... args) {
FilterCriteria criteria = new FilterCriteria();
criteria.setCategory("Books");
criteria.setType("Fiction");
try {
String response = exampleClient.filterWithBody(criteria);
logger.info("Response: {}", response);
} catch (Exception ex) {
logger.error("Error occurred while calling Feign client: {}", ex.getMessage());
}
}
Will result in a proper GET request.
GET /filter?category=Books&type=Fiction
Example Controller Endpoint
@RestController
public class FilterController {
@GetMapping("/filter")
public String filterItems(@RequestParam String category, @RequestParam String type) {
return "Filtered items in category: " + category + ", type: " + type;
}
}
Logged Output:
com.jcg.example.FeignTestRunner: Response: Filtered items in category: Books, type: Fiction
The FilterCriteria object is converted into query parameters using @SpringQueryMap, allowing the controller to receive them as expected and return a response, which avoids the issues of sending a GET request body and ensures full compatibility with HTTP standards.
4. Conclusion
In this article, we explored how to handle GET requests with structured data using Feign in Spring Boot. We saw that sending a body in a GET request is not reliably supported and can lead to errors, such as method not allowed exceptions. To address this, we demonstrated how to use @SpringQueryMap to convert an object’s fields into query parameters, enabling the Feign client to communicate properly with the server.
5. Download the Source Code
This article explored how to handle an HTTP GET request with a body when using Feign.
You can download the full source code of this example here: feign http get request body




