What is an API? Explained with Simple Analogies
You have probably heard of the term API a lot of times coined in between conversations, but you find it hard to understand the working and meaning of an API then you are at the right place. Let's break down what an Application programming interface really is.
API stands for application programming interface where:
- Application: Application is a software having distinct function (example: Facebook, Whatsapp, file manager, etc.)
- Programming: programming is a process of building a software.
- Interface: An interface is a point or place where two systems meet and interact.
So, this was the technical definition of API as the name suggests. If this is hard to gasp for you let us break down some analogies.
1. The restaurant waiter analogy.
This is the most simple and classic analogy to understand the working of API's although you are not in the technical field. Imagine you are about to order something from the restaurant after going through the menu.
- You (Application): You are an application here that needs to connect to the kitchen of the restaurant that is also an application, but it is inappropriate to directly ask the kitchen and doing this will create a mesh.
- Menu: menu consists of some predefined items that can be ordered, you can't order items outside the menu.
- Kitchen (Application): kitchen is also an application that is responsible for processing the order and sending it back to the table (you) as a response.
- Waiter (API): Waiter takes your order and passes it to the kitchen of the restaurant, after the food is prepared the food is carried to the dinning table by the waiter as a response.
As in this example we can see the direct process between kitchen and you was not efficient so a waiter is required that helped us do the process efficiently. An API works the same way, it takes request from one application, fetches information from another and give it back as response within some defined set of rules in a clean, predictable format.
Now, here are some real digital world example:
a. Delivery app (uses Google maps API)
As it is not feasible to create global mapping system due to high cost and less resource, Google provides API of their map to these website and cost them according to clicks. What actually happens?
- Delivery app → API: The Delivery website sends data to google server as a request with information such as current location of agent and customer.
- API → Maps : the API takes the request and sends it to the google maps
- Maps → API: Google maps provide the map with information to the API.
- API → Delivery app: The API shows the map as a response to the delivery app.
b. Sign in with google
There area several websites using authentication API of a third party services such as Google that helps user to not fill and remember multiple user-id and password across the web. Here’s what actually happens when you click that button:
- Website → API: You click "Sign in with Google" on the Spotify website. Spotify sends a request to Google's Authentication API, essentially saying, "Please verify this user for me."
- API → Google's Servers: The API securely transmits this request to Google's authentication servers. You are often redirected to a standard Google login page to enter your credentials.
- Google's Servers → API: After you successfully sign in, Google's servers create a secure token (a confirmation of your identity with basic info like your name and email) and send it back to the API.
- API → Website: The API delivers this token to Spotify. Spotify trusts the token because it came from Google, uses it to log you in, and either creates a new account for you or finds your existing one.
c. A Beautiful API Example: NASA's Picture of the Day
Some APIs provide visually stunning data. NASA offers a free API that delivers a new, high-resolution astronomy picture every day, complete with an explanation. Click the button below to see it in action.