API(Application programming Interface)

Vibha Thakur
3 min readFeb 7, 2021

I always wondered how a Google map, or a YouTube video shows up on a third party website? The answer is through the magic of APIs. Well maybe it’s not magic, just some cool programming.

APIs are the reason for many of the applications we use in our daily lives such as news app or any other application which provide us huge chunk of data from internet into Applications that are installed in our phones to provide seamless user experience.

  1. What is an API 🤔🤔-:

As i have already mentioned API stands for application programming interface. Basically i want to explain API in most laymen term so that anyone can understand the same without any confusion, hence i have a easy pizzy example for the same.

let’s imagine you are sitting in a restaurant, you can imagine waiter at a restaurant as an API. You need the waiter to communicate your order from you, at your table, to the kitchen where the food is made. The same is true with an API. The Waiter (the API) takes your order (the request) from your table to the kitchen (the system) and returns with your food (the response).

2. Why we use API in android development-:

  • Allow communication between server and Application
  • Send and Receive Response (Data) from server to user and user to server
  • Access data from server
Simple diagram to explain the API

3. Types of API

  • REST API stands for Representational State Transfer
  • SOAP API stands for Simple Object Access
  • ASP.net

4. What is REST API-:

REST API are most common use case of API, A RESTful API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.

Now you might be wondering, “what types of request can you make using a REST API?” Here are the standard types of requests:

  • Get- is a method to read or retrieve data from a system (our Google Maps example)
  • Post- is a method to create new data in a system
  • Put- is a method to update/replace existing data in a system
  • Patch- is a method to update/modify existing data in a system
  • Delete- is a method to delete data in a system

5. How to use REST API in an android project-:

Some days ago i built an android News application Using Retrofit library by consuming a News REST API. In next article i will make you understand the whole functionally and working of application and how data is being fetched from a REST API using Retrofit library.

Github link for the same is:-

For now we can understand the basics of application and how we to configure our android studio project for the same.

So, What is Retrofit🤔?

Retrofit is a REST Client library (Helper Library) used in Android and Java to create an HTTP request and also to process the HTTP response from a REST API. It was created by Square, you can also use retrofit to receive data structures other than JSON, for example Simple XML and Jackson. Before we continue, let’s briefly define REST Client and REST API in our context.

5. What are basic API implementation steps in a Android project-:

  • Create Android studio project
  • Add internet permissions in Menifest
  • Add Retrofit Library(or any other library that you are using) dependencies
  • Create Class for Retrofit instance
  • Interface for End Points
  • Create POJO(Plain old java Object) class for API response
  • Call API in activity/Fragment
  • Set data in XML View

Ok that’s it for now, in next article i will make you understand the whole working of my news application.

If you like please consider to clap 🙌 and also connect with me on Linkedin https://www.linkedin.com/in/vibha-thakur/

--

--