Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it.
Source: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html
With Feign, URLs are not hardcoded and Feign integrates with Ribbon and Eureka automatically. To use it you must add this dependency:
<dependency>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<groupId>org.springframework.cloud</groupId>
</dependency>
Then, you must add the @EnableFeignClients annotation to the main class and declare a Feign client using the @FeignClient annotation in the interface:
@FeignClient(name = "other-service-name")
public interface Proxy {
@GetMapping("/other-service-uri/{variable}")
public Response getResponse(
@PathVariable String variable);
}
Now, you can use it:
Response response = proxy.getResponse(variable);
For more information see: https://www.baeldung.com/spring-cloud-openfeign
Top comments (0)