70 points
7 3 1

How call REST Services in Android Application

Let’s start this project by creating a new project in Android Studios and name it *VolleyTutorial*.
Including the dependencies for the following in your build.gradle (Module:app).
Add Volley dependency :-
implementation '’

Add GSON dependency :- 
implementation '’

And now sync your project woth Gradle.

This is the open source API hosted whihc we will use for this tutorial :- You will get response like as below.

      "text":"To keep ReqRes free, contributions towards server costs are appreciated!"

You will need to make a model which will handle above response :-

public class ResponseModel{

private Data data;
private Support support;

private class Data{

private int id;
private String email;
private String first_name;
private String last_name;
private String avatar;

public String getEmail(){
return email;


private class Support{

private String url;
private String text;

public String getUrl(){
return url;


// Add getters and setters to get any variables which is private 

public String getEmail(){
return data.getEmail();

Now you will make a StringRequest via Volley and will add into RequestQueue and then we will parse it to process our next action.

Make one method named as a callRestServices() so we can manage it differently. And add below line.
public static final String URL = "";

StringRequest stringRequest = new StringRequest(URL, new Response.Listener<String>() {
    public void onResponse(String response) {

        GsonBuilder gsonBuilder = new GsonBuilder();
        Gson gson = gsonBuilder.create();
        RestModel restRes = gson.fromJson(response,RestModel.class);

        Log.d("Rest Service Response --->>> ",restRes.getEmail());

}, new Response.ErrorListener() {
    public void onErrorResponse(VolleyError error) {
        Log.e("MainActivity.class", "onErrorResponse: " + error.getMessage());

RequestQueue requestQueue = Volley.newRequestQueue(this);
Now call this method inside createView() Method like as below :

public class MainActivity extends AppCompatActivity {

    public static final String URL = "";
    RecyclerView recyclerView;

    protected void onCreate(Bundle savedInstanceState) {




And now add Internet permission for calling rest service in your manifest file.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

We are all set now run your application and check log you will get USer’s email id in response.




thank you for sharing this.
Today you have taught me something new. Great job. Continue to post :)

More Posts

How to make Navigation Drawer in Android ??? darshan1507 - Jun 10
What is an API ? Setup to create REST API maazmasood - Apr 20
Connect android studio to phone amna - Apr 5
How to configure Firebase project in your android application ??? darshan1507 - May 18
An OverView of Gradle Takele - Sep 10
Call of duty world at war zombies android amna - Apr 7
How to change theme in android application amna - Jul 5
How to Get Started with AdMob in Your Android App darshan1507 - Jun 7
How to get selected date from datepicker in android amna - May 25
How to store data in sqlite database in android example amna - May 24