-2

I'm looking for a good HTTP library for my android app. I've been using AsyncHTTP by loopj (and I've only ever used that), but it's making my app crash when the network connection is lost. Also, it doesn't meet my requirements well. So far, I've found okhttp by Square and volley by Google. But I'm not sure which suits my purposes better. The following would be my requirements,

  • Small frequent http request for JSON results
  • JSON parsing
  • Async operation with callback methods
  • Caching, with functionality for force re-fetch

Some insights into how these differ and what I should be using, would be immensely helpful.

Shashwat Black
  • 992
  • 5
  • 13
  • 24

3 Answers3

3

OkHttp is an HttpClient. If you want JSON parsing and callback methods you should use Retrofit which uses OkHttp internally. Both Retrofit and Volley are suitable for your requirements. Volley also has an image downloader in it but if you want image downloading when using OkHttp you need to use Picasso from square (which I suggest).

I personally suggest using Retrofit+Picasso. They are lightweight and perform really well and they have a decent documentation.

Nasir
  • 1,982
  • 4
  • 19
  • 35
  • I've been using Picasso in my project as well, and it's awesome. I'll look into `Retrofit`. Thank you. Can `Retrofit` also cache the requests? I'm avoiding going through the trouble to manage a local database. Is there even such a thing as HTTP caching, kinda like how `Picasso` caches the images? – Shashwat Black Dec 07 '14 at 17:47
  • @ShashwatBlack As long as I know you should handle the cache for http. You can take a look at this https://gist.github.com/swankjesse/5889518 – Nasir Dec 07 '14 at 17:57
0

I personally used Volley for caching purpose, and Picasso for image downloading.

RoboSpice is another library which will be useful for caching.

Check out bellow links to make final decision :

Comparison of Android Networking Libraries

Retrofit

RoboSpice vs Volley

Community
  • 1
  • 1
Paritosh
  • 2,097
  • 3
  • 30
  • 42
0

Combination of Robospice and Google Http Client/Spring/Retrofit (your choise) is what you are looking for. RoboSpice perform async requests by using one of this networking library with respect to Activity/Fragment lifecycle and also handle caching. JSON are parsed by this libraries.

viduka
  • 391
  • 4
  • 10
  • I looked for some examples on `Robospice` - `Retrofit` combination, but I can't find much. I downloaded the [sample app](https://github.com/octo-online/RoboSpice-samples/tree/release/robospice-sample-retrofit) from the github repo, but neither do I understand it, nor can I run it. Could you direct me towards some basic tutorials for beginners, so I can get started? – Shashwat Black Dec 08 '14 at 03:46
  • Here https://github.com/stephanenicolas/robospice/wiki is wiki and here https://github.com/stephanenicolas/robospice/wiki/Starter-Guide is basic tutorial. Should help. – viduka Dec 08 '14 at 09:31