How APIs work ?
Tags: webdev, api, opensource, javascript
Published: 2020-11-07 09:41:35

![How API works- Vikas Singh](https://dev-to-uploads.s3.amazonaws.com/i/wmh64qtufi6l1y6m13at.png)

hola, amigos!

I got an overwhelming response on my previous post- [How AJAX works](https://dev.to/vkassingh/how-ajax-works-1nae). Now its time to learn about APIs and how they work. As soon as API came into the picture, developers got much more productive than they were before when they had to write the code from scratch.
__Now they don't need to reinvent the wheel.__

__Today we will learn:__
How APIs work with real-life examples.

Without any further due, let's get to the main point.

__What is an API?__
API stands for Application Programming Interface. So API  sits between two entities and facilitates the exchange of information/data/any kind of service between these two. 

__In Layman:__
It acts as a medium of communication between the user and the other party(server/database).

__Examples: __
1. Open Weather Map API which provides all the weather forecasts and updates. Like if you are a new developer who wants to develop a working weather app. Then you must use an API which will save tonnes of your time. 

__NOTE:__ You can use this time to add more features to your application.

2. Yahoo Finance API to fetch or scrape the stock market news and updates.

3. NASA API  to fetch statistics like Asteroid Stats, Earth Imagery, Pictures of Space, moon, stars and a lot more.


__NOTE__: You get raw data from API as a response. That data is slightly difficult to understand for the users. So as a developer, we need to parse that raw and unstructured data into JSON like format. This will make the data more readable and more meaningful to the end-user/client.

__How APIs work actually?__

__Example1__: The most common example which is used to explain --How APIs work is the metaphor example of __Customer, Waiter and Kitchen__

Just imagine, you went to a restaurant as a customer. There is a waiter. Now this waiter will work as an API here if you want to know how! , go ahead.

Now you as a customer, you are sitting on the dining table. You finalized a dish you want to eat from the food menu. Then you called the waiter(API) and requested(Request) him your order(some sort of data). The waiter then goes to the kitchen(database/store) and takes your order(data). The order is then delivered to you (user). 

__The API[waiter] comes into the picture in order to connect the user[cutomer here] to the database[Kitchen here].__


__Example2__: Now it becomes easier to understand the other examples for you.
Just imagine, you want a bank to get the latest details of your bank statement. So you approached the banking official who did something on his/her system you don't know. And boom! , he/she gives you the details you want to know.

__Example3__: You ordered something online from any eCommerce site like Amazon or Flipcart. That order is then processed and you don't care about the processes it goes through. And then finally your product is home delivered by an Amazon delivery boy. So you got what you ordered.

Hope these 3 examples cleared the picture on How __APIs work?__

Connect with me on
Instagram
https://www.instagram.com/p/CFqrvobFlsL/?igshid=j3lhn2qi3og0

Twitter
https://mobile.twitter.com/_SinghVikas_