In the Feign microservice call, you can make a POST request by adding parameters after the URL. Parameters can be passed in two ways: as path parameters or query parameters.
Path parameter: You can add parameters to the path of the URL and use the @PathVariable
annotation to get the value of the parameter. For example:
@FeignClient(name = "example-service")
public interface ExampleFeignClient {
@PostMapping("/example/{param}")
void postWithPathVariable(@PathVariable("param") String param, @RequestBody Object body);
}
-
In the above example,
param
is the path parameter, which can be obtained through the@PathVariable
annotation. The@RequestBody
annotation is used to pass the request body as a parameter to the POST request. -
Query parameters: You can add parameters to the query string of the URL and use the
@RequestParam
annotation to get the value of the parameter. For example:
@FeignClient(name = "example-service")
public interface ExampleFeignClient {
@PostMapping("/example")
void postWithQueryParameter(@RequestParam("param") String param, @RequestBody Object body);
}
-
In the above example,
param
is the query parameter, which can be obtained through the@RequestParam
annotation. The@RequestBody
annotation is used to pass the request body as a parameter to the POST request.
When using Feign to call microservices, you can choose a suitable method to pass parameters according to actual needs. Whether it is a path parameter or a query parameter, you can add parameters after the URL to make a POST request.