Declarative REST Client - Feign

Feign helps us create REST clients for REST services with minimum configuration and code. All you need to define is a simple interface and use proper annotations.

RestTemplate is typically used to make REST service calls. Feign helps us write REST clients without the need for RestTemplate and the logic around it.

Feign integrates well with Ribbon (client-side load balancing) and Eureka (Name server). We will look at this integration later in the chapter.

To use Feign, let's add the Feign starter to the pom.xml file of service consumer microservice:

    <dependency>      <groupId>org.springframework.cloud</groupId>      <artifactId>spring-cloud-starter-feign</artifactId>    </dependency>

We need to add dependencyManagement ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.