Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why to use Retrofit? [closed]

I am building a news application and I receive news in JSON format.

One of my friends recommended me to use Retrofit, but I did not understand why I should use Retrofit library instead of just handling Json with Gson myself.

Is there some advantage of Retrofit that I am not aware of?

like image 499
Abdurakhmon Avatar asked Apr 19 '17 09:04

Abdurakhmon


People also ask

What is the advantage of Retrofit?

Retrofit is a type-safe HTTP networking library used for Android and Java. Retrofit was even better since it was super fast, offered better functionality, and even simpler syntax. Most developers since then have switched to using Retrofit to make API requests.

Why do we need Retrofit interface?

Retrofit uses interfaces to define the possible http operations. public static Retrofit getApiClient(){ if (retrofit==null){ retrofit = new Retrofit.

Why do we need OkHttp with Retrofit?

For making HTTP requests Retrofit uses the OkHttp library. OkHttp is a pure HTTP/SPDY client responsible for any low-level network operations, caching, requests and responses manipulation. In contrast, Retrofit is a high-level REST abstraction build on top of OkHttp.

How Retrofit is better than volley?

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. On the other hand Retrofit does not provide any such feature, Other libraries such as picasso or glide is recommended to perform image loading.


3 Answers

Retrofit will save your development time, And also you can keep your code in developer friendly. Retrofit has given almost all the API's to make server call and to receive response. internally they also use GSON to do the parsing. you can go through this link you will get more info http://vickychijwani.me/retrofit-vs-volley/

like image 200
Harshitha Avatar answered Sep 21 '22 06:09

Harshitha


Developing your own type-safe HTTP library to interface with a REST API can be a real pain: you have to handle many aspects, such as making connections, caching, retrying failed requests, threading, response parsing, error handling, and more. Retrofit, on the other hand, is a well-planned, documented and tested library that will save you a lot of precious time and headaches.

Volley v/s Retrofit see this link

http://vickychijwani.me/retrofit-vs-volley/

compile 'com.google.code.gson:gson:2.6.2'

compile 'com.squareup.retrofit2:retrofit:2.1.0'// compulsory

compile 'com.squareup.retrofit2:converter-gson:2.1.0' //for retrofit conversion

like image 43
Keshav Gera Avatar answered Sep 19 '22 06:09

Keshav Gera


Retrofit 2 is great networking library for modern Android apps, but each has its own strengths that is worth weighing for critical projects. Use Retrofit if your use-case is a standard REST API with JSON responses and not too many custom requirements in terms of caching, request prioritization, retries, etc.

like image 35
HosseinBahrami Avatar answered Sep 21 '22 06:09

HosseinBahrami