I got an overwhelming response on my previous post- How AJAX works. 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.
It acts as a medium of communication between the user and the other party(server/database).
- 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.
Yahoo Finance API to fetch or scrape the stock market news and updates.
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