retrofit – Why should I use OkHttp instead of android httpClient and AsyncTask-ThrowExceptions

Exception or error:

In the presentation of Paresh Mayani at SpeakerDeck ( he says that it’s better to use OkHttp or Retrofit instead of AsyncTask with DefaultHttpClient.

My question is why?
Why are they faster?
Aren’t those also libraries based on the default android classes?
What is the difference between OkHttp and Retrofit ?

How to solve:

As always, engineering is about balancing the trade-offs to build the best solution for your requirements.

Using a library instead of the platform is a good example. The API of the platform has existed for quite some time, and for compatibility reasons the Android team has less flexibility in changing those interfaces. A library doesn’t have those constraints; for example, if the host supports it OkHttp can use the SPDY protocol for lower latency, compression, multiplexing, etc., which can make your Android app more responsive.

OkHttp and Retrofit – which are projects from Square – can work together. They are also regular Java libraries, so they do not depend on / based on Android. OkHttp handles the lower-level HTTP connection details, while Retrofit simplifies using REST APIs. Retrofit can be used on top of OkHttp, but it is not required.

Check out the projects websites, they are also hosted on github.

Leave a Reply

Your email address will not be published. Required fields are marked *