Here is a new simple and easy option for making network requests. In comparison to volley this one is bit fast following is the test result that depicts the same.
This awesome library is Retrofit multiple versions are available as the development is done since lot of time, at the time of writing this blog its current version is 2.0.
While working with retrofit we need to create three classes
Modal Class - where the data is stored in its corresponding variable received from network.
Interface - An interface is required that will manage the get, post. etc requests.
RestAdapter Class - This is the RestClient class.
As mentioned earlier using this library is pretty simple
Add this library to your project by adding following line into your compile statement
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
and make the request as follow.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.nuuneoi.com/base/")
.addConverterFactory(GsonConverterFactory.create()) .build();
service = retrofit.create(APIService.class);
The best part is you need not to use the Gson module as the only because with retrofit you can use any of the following libraries to parse your response.
Gson Jackson Moshi Protobuf Wire Simple XML
and most importantly we can create our own converter by using Converter.Factory interface.
(This will be discussed in my next blog).
0 Comment(s)