Communication between app and server is a much very important task which needs to be carefully handed using a fastest and much efficient library to make this process much easier for even the novice.In this Android Tutorial on Retrofit Library we will learn how to post data into server using this library.

 

We will be using a local server for this tutorial so if your are not aware of the local server usage and installation please refer below tutorials for any further.

 

Android Installation of Local Server || Local Host || Wamp Server Installation

 

Add Retrofit to your project

build.gradle(Module:app)

 

activity_main.xml

Create a simple user interface to insert data, add required fields.

 

and then lets start coding further

 

ApiUtils.java

Create a utility file where you can add your api url.

 

 

APIService.java

In service class mention your parameters i.e., our key values by using which you want to fetch values

 

 

RetrofitClient.java

Configuring your retrofit client accordingly

 

 

MainActivity.java

Initialize Service

Now for sending post request using retrofit

 

 

AndroidManifest.xml

 

 

Output

 

Show Buttons
Hide Buttons
Read previous post:
Installation of Local Server || Local Host || Wamp Server Installation

Close