What is the difference between Resttemplate for Spring boot Feingclient?

Asked

Viewed 871 times

1

I came across a question:

  • What is the difference between the RestTemplate (I never implemented) and the FeingClient (I’ve already implemented)?

I realized that the two have the same or similar purpose, but it seems simpler to implement the FeingClient. Is there any situation where one is better than the other?

1 answer

0


Good Fernando, as you said, seems to have the same purpose. I have already had the opportunity to implement both models in Spring. What served me as a criterion for using one or the other was really the purpose.

Where I used the Feign, and why did I use it? As you may have noticed in your Feign implementation, it is very easy to create interfaces between your application and other services, specifying paths and methods very clearly via annotations. It is also facilitated the handling of error and other returns through the configuration of Decoders. So in situations I want to make a kind of "interface" between the application To and the application B going through an API of mine I use Feign.

Already the RestTemplate, I usually adopt when I need to make a punctual call to an external service my application, considering that it has a simple implementation to do, without need of extra settings as can be seen in the example below.

        RestTemplate restTemplate = new RestTemplate();
    String fooResourceUrl
            = "http://localhost:8080/spring-rest/foos";
    ResponseEntity<String> response
            = restTemplate.getForEntity(fooResourceUrl + "/1", String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

A good documentation on the implementation of a Resttemplate can be seen here The Guide to Resttemplate.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.