
Then we create Retrofit instance and set base url and converter factory and call interface method which interact with API on background thread and success of API can be get in onResponse() method of enqueue call back.Failure of API can be get in onFailure() method of enqueue call back.After that pass the list of country at adapter as in method setUpAdapterView() of example.

From asynchronous execution on a background thread, to automatic conversion of server responses to Java objects, Retrofit does almost everything for you.
RETROFIT ENQUEUE CODE
In below example, we are going to display country name and country code in RecyclerView.įor which as in createRetroFitBuilder() method of example first we set header using OkHttpClient class because API is authenticate api (set header only if api is authenticate). Retrofit offers you an extremely convenient way of creating and managing network requests.

Retrofit use the model class for parsing the server response by using convertors like Gson, Jackson. Retrofit need a model class (POJO) for sending and receiving request. Interface – public interface // use if api is post. You have to specify base url and converter factory at the time of Retrofit instance creation as in the below example. You can create Retrofit instance by Retrofit.Builder().

Retrofit mainly need three things which are following- 1. Adding Dependency in adle- dependencies Adding Internet Permission in Manifest. It is a very easy and fast library to retrieve and upload the data via Rest based web service. It is a simple library that is used for network transaction. Most of our 10.8 billion existing homes are in need of a retrofit to improve their performance and cut household energy use and emissions.
