Mobile app includes some sort of network hits to perform its functionality and there are many alternatives available to perform network operations. Such as Retrofit and Volley , But what are the differences between them ??? Not to worry Just Scroll down.
Code Complexity :-
Both Retrofit and Volley are easy to use and provides the feature to make network calls both synchronously and asynchronously.
- Retrofit treats the API calls as simple java method calls and it also handle the Json/Xml parsing itself.
- In Volley we have to do some extra code to achieve the same for parsing(need to create a custom request).
Inbuilt Types :-
The data returned by an Api plays vital role in implementation of network call and its handling.It is one of the important parameter to decide which option we should use.
Volley can capture four types of responses automatically through these requests:
- StringRequest – Converts the response into a String.
- JsonObjectRequest – It's request and response is automatically converted into a JSONObject.
- JsonArrayRequest – It's request and response is automatically converted into a JSONArray.
- ImageRequest – It;s request converts the response into a decoded bitmap.
- JsonObjectRequest – It's request and response is automatically converted into a JSONObject.
- JsonArrayRequest – It's request and response is automatically converted into a JSONArray.
- ImageRequest – It;s request converts the response into a decoded bitmap.
Retrofit can parse many other types of responses automatically like:
Boolean – Web API response needs to be a boolean.
Integer – Web API response needs to be an integer.
Date– Web API response should be Long format date.
String – Web API response needs to be in String format.
Object – Web API response needs to be in Json object.
Collections – Web API response needs to be in a String Format.
Boolean – Web API response needs to be a boolean.
Integer – Web API response needs to be an integer.
Date– Web API response should be Long format date.
String – Web API response needs to be in String format.
Object – Web API response needs to be in Json object.
Collections – Web API response needs to be in a String Format.
Image Loading :-
- Volley has an inbuilt support for image loading.It is packaged with a loader a custom view called NetworkImageView which is specially designed to download and show images.
- Retrofit does not provide any such feature, Other libraries such as Picasso or glide is recommended to perform image loading.
- Retrofit does not provide any such feature, Other libraries such as Picasso or glide is recommended to perform image loading.
Caching :-
Volley has a very elaborate and flexible caching mechanism.When a request is made through volley first the cache is checked for appropriate response if it is found there than it is returned and parsed else network hit is made. Retrofit does not support caching.
Volley has a very elaborate and flexible caching mechanism.When a request is made through volley first the cache is checked for appropriate response if it is found there than it is returned and parsed else network hit is made. Retrofit does not support caching.
Retrying mechanism :-
With Volley we can set a retry policy using setRetryPolicy method. It support the customized request timeout, number of retries and back off multiplier.
- Retrofit does not support any retrying mechanism.But it can be achieved manually by doing some extra code.
With Volley we can set a retry policy using setRetryPolicy method. It support the customized request timeout, number of retries and back off multiplier.
- Retrofit does not support any retrying mechanism.But it can be achieved manually by doing some extra code.
Request Cancellation :-
Both Volley and Retrofit supports request cancellation.
Both Volley and Retrofit supports request cancellation.
Post Requests and Multipart uploads :-
Volley supports both post requests and multipart uploads but for post requests we have to convert our java objects to JSONObject. Also for multipart uploads we have to do some extra code and use some additional classes.
Retrofit has full support for Post Requests and Multipart uploads.
Volley supports both post requests and multipart uploads but for post requests we have to convert our java objects to JSONObject. Also for multipart uploads we have to do some extra code and use some additional classes.
Retrofit has full support for Post Requests and Multipart uploads.
Nice...keep writing:-)
ReplyDeleteGreatly summarized!!!
ReplyDeletegood
ReplyDelete