Sending HTTP Request Using Retrofit

Retrofit is a most popular HTTP client for android application for API call.This library is useful for sending Get,Post,Put, & Delete method over HTTP.

We can also send the HTTP request using HTTP Client,Volley library,so the main question is,why we should use Retrofit library for this networking call?


Advantage
  • Retrofit makes easier to consume Restful web service.
  • Its is very easy to configure.
  • We don't need to handle web exception.Whereas it controls all web exception.
  • It save our development time.

Implementation

Before using retrofit client we have to add the dependency inside our android project.

Step 1:

  • Expand your android project and navigate to: Gradle Script > build.gradle(Module App)


  • Open the module level gradle file and paste the following line inside dependencies bracket:
     implementation 'com.squareup.retrofit2:retrofit:2.3.0'
     implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
Step 2:
These are two dependency,Retrofit and Gson converter.After adding this two line,we need to download the dependency.So click on the Sync option from the top  right side corner.
Its done.So here we successfully added retrofit library inside our project.Now we can use this library
for sending the HTTP request to API.


Sending HTTP Request Using Retrofit Sending HTTP Request Using Retrofit Reviewed by SP Tutorials on November 28, 2019 Rating: 5

No comments:

Powered by Blogger.