DEV Community

eidher
eidher

Posted on • Edited on

Spring Cloud OpenFeign

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>
Enter fullscreen mode Exit fullscreen mode

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);

}
Enter fullscreen mode Exit fullscreen mode

Now, you can use it:

Response response = proxy.getResponse(variable);
Enter fullscreen mode Exit fullscreen mode

For more information see: https://www.baeldung.com/spring-cloud-openfeign

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs