How do you explain API to a 5-year-old?
A few days ago my partner and I were having a random technical discussion. I realized that my son had overheard us when he started using the word ‘API’ and started singing like a rhyme. He asked me, “what is an API Mumma? Is this a new chocolate you will buy for me?”. I ignored him with a kiss and got busy with my work.
Having worked in API testing for a few years now, I realized that I should have actually explained to him at least the meaning of API in very simple words. The truth is I did not find any simple words to explain him. I can just think of ‘Application Programming Interface’- the full form of API. I took it as a challenge to test myself how much do I actually know. How do I actually explain to someone who does not have any idea of the topic?
“If you can’t explain it to a six year old, you don’t understand it yourself.” — Albert Einstein
In the late afternoon same day during our storytelling time, I told my kid that I will tell you a story about API today. So this goes my approach to explain him:
I asked my kid what do you want to have for snacks today. He was ready with his instant answers- choco pie, kinder joy, and Lays Green chips.
Me: You have to promise me that you will study today. When you sit at your study table, I will go to the shop and buy the items for you. I will tell Uncle shopkeeper to give your favorite chocolates and chips.
Kid: Promise Mumma. I will study. But first, tell me the story of API.
Me: So as you have to study in the evening, you cannot go with me and talk directly to the Uncle shopkeeper. Who will be talking on your behalf with the shopkeeper?
Me: Yes. Mumma will ask the shopkeeper to give you chocolates and chips and the shopkeeper will give the chocolates to Mumma for you. When you and the shopkeeper cannot talk directly, Mumma brings it for you. When two persons cannot talk directly, we take the help of an API. So here API is your Mumma. API is not your chocolate but the way to get your chocolate. Do you understand API now?
Kid: Yes, API is Mumma who will bring chocolates for me from Uncle shopkeeper.
API acts as a middle man when 2 parties cannot communicate directly. With the help of API, 2 parties can communicate.
After listening to me for a few minutes, my kid got busy in his own world. But I thought let me extend a few more things about API and will tell him the next day. The next day conversation follows :
Me: Do you know in which language Mumma and the shopkeeper talked while buying your chocolates.
Kid: Hindi, English…and…
Me: Right! Similar to Hindi, English, etc, API has its own language by which it talks. API does not know Hindi or English. It uses various other languages like “GET”, “POST”, “PUT”, “DELETE”, and a few numbers (200, 201, 401, 500, etc)to communicate according to its various needs.
Mumma API uses “GET” language to talk to the shopkeeper and the shopkeeper understands what you are asking for and gives Mumma “Kinder joy” and “Lays Green chips”. But he said he does not have choco pie. When he has something in his shop, he says 200 OK and when he does not have it he says 404 Not found. So for Lays chips and Kinder joy, he says 200 and for choco pie, he says 404.
API uses GETto read(retrieve) information from one party and gives information to the other party
Me: The shopkeeper does not have the choco pie. But you want it right?
Kid: Yes, it is yummy
Me: I have asked the shopkeeper to bring choco pie for you and I will collect it on some other day. In this case, Mumma API has used the “POST” language to talk, tells him how yummy choco pie is, and brings a new item to the shop. The shopkeeper told me he will bring the new item and said “201 Created”.
API uses POSTto send data and create a new resource.
Me: You know when I was buying your chocolates, I checked the items and saw that one kinder joy was spoiled. It has reached its expiration date. So I again talked with the shopkeeper to replace it and give me a new one. In this case, Mumma API has used “PUT” language to make changes to the existing item in the shop. So the shopkeeper replaced the item and said “200 Updated”
API uses PUTto send data to edit/update an existing resource
Me: What will happen if the shopkeeper will give the spoiled ones to your friends?
Kid: Yes, what will happen then.
Me: Do not worry. I have told the shopkeeper to remove all the kinder joy packets from the shop which have reached their expiration date so that he does not give those spoiled packets to any of your friends or to anyone buying from that shop. In this case, Mumma API uses “DELETE” to remove all the existing items which are spoiled.
API uses DELETEto delete an existing resource
API uses various codes to represent the request status like 2xx,3xx,4xx, 5xx .
I don't know how much a kid can actually remember about an API from the above explanation. I hope someone new to API can relate and understand the basics of an API from this article.