When to use Open Feign and when not?
spring boot - What are the advantages and disadvantages of using feign over RestTemplate - Stack Overflow
java - Spring Boot 2 - Unsatisfied dependency on Feign client when autowired for service - Stack Overflow
Introducing SpecMock: Easily create mock Server for @Controller and @FeignClient in exist class!
I want to write a simple REST POST API , this will be invoked by cross team to send json data and then I have to process this data and give status OK back as response, if validation passes.
Since I am going to use all new tech stack, Java 21, Spring 3.2.5 I am confused on using Open Feign .
Since REST template is deprecated I want to make choice between open feign and wen Client.
-
will it be good to use Open Feign here in above small use case ?
-
Does cross team who willing to call my endpoint have to write code using Spring cloud open feign too?
-
Any other cons to consider?
Feign allows you to abstract the mechanics of calling a REST service. Once you configure and annotate the Feign interface, you can call a REST service by making a simple Java function call. The actual implementation of making a REST call is handled at runtime by Feign. This means that the implementation can be configured without changing your business logic code.
By just changing the Feign configuration in Java or using properties you can add encoding/decoding, logging, and change the REST call implementation library. All this is done through configuration only, while the business logic that calls the service remains unchanged.
Since Feign uses standard Java interfaces, it's also easy to mock them during unit tests.
There are certain advantages.
1.URLs are not hardcoded.
2.you don't have to write unit test cases for feign as there is no code to test however you have to write integration tests.
3.we can use Eureka Client ID instead of the URL.
4.Feign handled the actual code.
5.Feign integrates with Ribbon and Eureka Automatically.
6.Feign provides a very easy way to call RESTful services.
There was an issue in feign client before. I guess you are experiencing the same maybe because you are using an old version but what you should do is including the pathVariable name in your @PathVariable annotation like this
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
String hello(@PathVariable(value = "name") String name);
You can find the details from here
When you using rest feign client service we need to define exact @Pathvariable name.
@GetMapping("/hello-world/from/{from}/to/{to}")
public String getHelloWorld(@PathVariable("from") String from, @PathVariable ("to") String to);