What are the advantages and disadvantages of using feign over RestTemplate

codingsplash picture codingsplash · Oct 23, 2017 · Viewed 13.3k times · Source

I get that Feign is declarative and hence it abstracts out a lot of things for the developer. But, when should one choose one over the other? Though feign is declarative, it has serious problems with oAuth. What are some of the considerations in using RestTemplate over Feign

Answer

Gonen I picture Gonen I · Mar 17, 2019

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 a 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.