How To Connect to a RESTFUL API on Android using Java


Feeling Restful? Well, gas up! Because we are about to Launch. This project is a very simple Android Project aimed at getting you to implement some simple concepts that are very important as far as Android Development is concerned.
In this project, you are going to implement a mobile design of the GADS 2020 Leaderboard.

The mobile App will display the Top 20 learners in the Learning Leaders’ category and Top 20 learners in the Skill IQ Leaders’ category. We are going to Fetch Data From an API(Application Programming Interface) which is hosted on Heroku and Display Data on The Mobile App, sounds interesting? We just getting started. This project is for beginners, intermediate and senior developers who would want to get their hands dirty on  Restful APIs on Android    you can get the hosted API here as well as the endpoints we are going to use.

This Project will make you understand

  1. Multi-Activity
  2. View pager
  3. Customizing Toolbar
  4. RecyclerView
  5. Adapters
  6. Making Network Request using Retrofit to an endpoint through a @GET request

what it looks like sending requests through a mobile client and getting response from the api web service


  1. Some Basics on Android mobile development
  2. Basic fundamentals on Java Programming Language
  3. Basic Design Concepts

Photo by Windows / Unsplash

What you need to get started

  1. install android studio
  • you are set to go!

Download Android Studio and SDK tools | Android Developers
<!– hide description –>

  1. First, open android studio and create a new project
    First, start a new Android Project by going to File > New project or just tap the Create New Project button on the start page of your Android Studio.
    2. Choose Empty Activity as your project template, then click next.

    Give any name to your project, in my case I named it LeaderBoard for this project and then click finish and wait until the project build successfully.

  1. Now add the following dependencies on the build.gradle(Module :app)

Now when you are done sync the project and wait for build to finish successfully

This is How Your Manifest File Should Look Like remember to add internet permissions

Let’s Get the Layouts done
  1. learning_leaders_fragmet Layout xml file
  2. skill_iq_fragmet Layout xml file


Create a new Java class and name it viewpageradapter this class will assist us is scrolling between two tabs which are skill_iq tab and learning_leaders tab the class extends FragmentPagerAdapter

here is a snippet code…

Next, let’s create a new Package under Java Folder and name it Model then inside Model lets create two Java Classes

1 LeaderBoard java class

Here is a snippet code…
NB make sure you use Serialize

2.SkillIQ Java Class

here is the code snippet…

Now we are going to make two fragments by creating the corresponding Java classes which will extend Fragment

  1. learning_leaders fragment
  2. skill_iq fragment

1.Learning leaders fragment which extends Fragment

here is a code snippet…

2.skill_iq fragment

code snippet..

Error when loading gists from

Great we are almost done hold on for a while!!!

The next Step is making adapters package and creating the two adapters

  1. SkillIQ adapter

code snippet…

code snippet…

Let’s create a Service package and inside the package lets create.

  1. ServiceBuilder Class
  2. SkillDataService java interface
  3. LearningLeaderService java interface

1.ServiceBuilder Class

code snippet..

2.SkillIQDataService java interface

code snippet…


code snippet…

Finally here is where the Magic happens

We are going to make a request inside the respective learning_leaders fragment and skill_iq fragment and set the adapters as well as the Recyclerview. Inside OnViewCreated, we are going to retrieve data from the base URL and display the data

1.First let’s make the request on the learning_leaders fragment inside the OnViewCreated

code snippet…

NB make sure you initialize the RecyclerView, LearningLeadersAdapter and the List as follows inside the learning_leaders fragment
and add a constructor

here is the data that will be displayed

2.Second and final step lets repeat the same process for Skill_iq fragment

code snippet…

Here is what will be displayed

Find the GitHub Repo HERE


You May Also Like
Read More

APIs: The Web’s Legos

Over the past two years interacting with developers and businesses, one question found its way whenever conversations begin;…