One day Mickey was working in his garden when he saw Minnie going down the street
Mickey – Hey! Minnie
Minnie – Hi Mickey. How are you?
Mickey – I am good. What’ up!
Minnie – Nothing!
Mickey – Common, you can tell me
Minnie – I keep hearing this word API everywhere but do not exactly know about it. I want to know everything from scratch
Mickey – Oh just that, I will tell you a story
Minnie – Wait, can you come with me to the beach, I was actually going there
Mickey – Even better. Let me take Pluto too. Let’s go.
(Mickey & Minnie went to the beach)
Mickey – It is so nice here
Minnie – Yes it is
Mickey – Okay, Minnie, suppose you goto a restaurant. Can you tell me the process of ordering food?
Minnie – Well it’s easy. I will call the waiter and give my order. He will then communicate my order to the kitchen. The chef will prepare the food and the waiter will bring my food to my table. That’s it
Mickey – Exactly. Now here, there is a person who communicates your request (order) to the kitchen and then brings your order to you. Who is this person?
Minnie – He’s the waiter
Mickey – Yes, Now you can imagine API as a waiter or an intermediary between you (client) and the kitchen (server) and helps to communicate your order (request) to the kitchen and then brings your food (response) to you
Minnie – I am getting this
Mickey – So you see here is a client and a server and client sends request and server sends a response and this communication is facilitated by API
API = Application Programming Interface
Minnie – I have a question
Mickey – Yes, please
Minnie – We also have self-service these days. I can order and collect my food directly without the need of a waiter. In that case, the waiter is not required
Mickey – Very good question. Now imagine you speak English and the chef in the kitchen speaks French and you need someone for communication. And the waiter is the person who can do this
Minnie – I see that, so does API helps communicate between two applications that are built with different programming languages.
Mickey – Yes, and not just language, the applications can be built on different platforms(operating system), using different servers and databases as well
Minnie – So how can 2 different systems talk to each other there must be some common protocol
Mickey – Minnie, you just said the right thing, But I will tell you about it later
Minnie – Okay, I have a question. Why this name – Application Programming Interface
Mickey – Take an example, if you write a program in C language to print “Hello World”. Now you can run the same program on windows and on Linux, even though both these executables use different system libraries to display “Hello World” on the screen, you need not worry about the underlying library implementation as C language provides API like STDIO.h to take care of this.
So in a way API provides an interface to your applications program
Minnie – I did not get that
Mickey – An API(Application Programming Interface) is a set of defined functions and methods for interfacing with the underlying operating system or another program or service running on the computer to hide complexity or implementation.
Minnie – Okay a bit difficult but I will stay with the earlier example. That’s easy to understand
Mickey – Okay, Minnie, let’s take another interesting and real-world example. Let’s say you need to travel and have to book flight tickets. What will you do
Minnie – I will probably go to a travel website like Expedia and provide my details like date, origin, destination, no of passengers and search for flights
Mickey – Exactly, now what will you get in response
Minnie – I will get flight options from all the airlines
Mickey – So what do you think, how can a travel website like Expedia get information from all these different airline applications and show you the results
Minnie – Maybe it has access to the Database of these airlines applications
Mickey – Do you think that will happen in the real world. No application will allow direct access to its Database to any 3rd party. especially airlines application
Minnie – Yes, you are right. Can these airline applications dump their public data to some commonplace (DB) every minute and from there Expedia can get information
Mickey – Can do this, but the status of a flight can change any second. Do you think this will work?
Minnie – I guess No!
Mickey – So here we use API for this communication
Minnie – I guessed
Mickey – yeah, So here airline applications have exposed some APIs using which any 3rd party can get information that the airline’s application allows publicly
Minnie – I see. But how exactly is the api request looks like
Mickey – API request is like a document with key and values in some specific format like XML, JSON, etc.
Minnie – I see
Mickey – It can have additional information like authorization using some credentials, type of content etc
Minnie – Okay!
Mickey – so you see using an API or common format for communication, there can be an interaction between travel websites and airline applications. The API response gets the realtime information of the flights.
Minnie – This is interesting. I hear about REST and SOAP often these days, Are these API
Mickey – Yes, API is a broader term. REST and SOAP are web API or Web Services. So you can say they are API for the web for communicating between 2 applications over the web
Minnie – So in the airlines’ example, the communication must have happened using a SOAP or REST API.
Mickey – Exactly
Minnie – Feeling good now
Mickey – Now to enable applications to talk to each other there must be some rules, guidelines, and protocol
Minnie – Yes, that’s what I was asking earlier
Mickey – Yes, let’s take an example of REST and SOAP APIs. There are some format and guidelines of REST and SOAP
So basically to enable a communication we need a medium and a format
For example, when you talk to your friend over the phone, the phone is the medium and the language (English) that both of you understand is the format
In the same way in SOAP web services medium is internet or HTTP and most commonly used format is XML
In the case of REST, the medium is internet or HTTP and format can be XML, JSON, jpg, etc
Minnie – I am getting this
Mickey – Glad to know this
Minnie – I am now ready to go deeper with API
Mickey – I will suggest watching this – API for Beginners
Minnie – I will surely do that
Mickey – Do you want to go and play on the beach?
Minnie – No, I just want to sit with you and watch the sunset. Thank you, Mickey.
Mickey – I am always here for you 🙂