An API is a super simple concept that can be explained with everyday examples. Consider an API as the “menu” in a restaurant. You, or in this case, your computer, are the customer. The kitchen is like a data server you want to get data from. The menu lists all the dishes you can order, just like an API lists everything you can request from a data server. Without APIs or a menu, you wouldn't know what kind of food is available on the server and a way to order them.
Here's how it works:
First, there is a concept of an endpoint in an API. Like each dish on the menu has a name, each task you can ask the API to do has a specific "address" on the internet, known as an endpoint. For example, if you see “pizza” listed on a restaurant’s menu, you can order it, and if it's not listed, you simply cannot. So, endpoints tell you what you can or cannot do with the API.
The next concept is what’s called the HTTP Method. You can interact with your dish—eat, share, or send it back. In API terms, you commonly use GET to read data, POST to add new data, PUT to update data, and DELETE to remove data. In our example, GET is like happily eating food. POST is like asking to add more salt to the dish. PUT is for the picky eaters who customize their meals. And DELETE is for those "Oops, I didn't mean to order that" moments. So, the HTTP Method tells the API what type of action the user requests.
Another concept is the Request and Response. You place your order or make a request, and the kitchen cooks it up and serves it to you or sends a response. The response usually has a status code. “200 OK” means "all good," while something like 404 Not Found means "we can't find what you're asking for." This simply means that when you order a pizza at a restaurant and if they can serve it, the server says, “Yes! We can absolutely get you a pizza”. But when you get a 404, you are told, “Sorry, we are a Chinese restaurant, and we don’t serve pizza.”
Most of the time, the data you get back is in JSON, a standardized way of writing down data so both sides understand it. It's as if everyone in the restaurant spoke the same food language. It’s like using English almost worldwide because you don’t know the local language.
An API can also ask for Authentication. Sometimes, you need a "VIP Pass" or a special key to access certain parts of the API—sort of like needing to show you're of legal age to order a drink. Or, let’s say you are at this restaurant where you have to be a member to eat. They would ask for your membership card while you order from the menu. This step is crucial to keep unnecessary traffic out of the server and only let identified members in.
Just like you can't order the entire menu in one go, many APIs limit how many requests you can make in a certain amount of time to prevent overloading the system. For example, McDonald's can ask you to park your car on the side while you are ordering too many things from their drive-through. They don’t want all other customers to wait just because you had a big order.
So, whenever you're using an app or website that's pulling in data from somewhere else, like showing you the latest sports scores or your social media feed, it's usually using an API to request and receive that information, all in real-time. In simpler words, an API is an interface or a messenger between you and the data source. Like how a restaurant employs servers to connect customers to the kitchen, APIs connect client apps to the data source. By exposing APIs, a data source is easily accessible by various clients, ranging from mobile apps to websites to mapping systems in your car. The API maker, in this case, can charge the clients and generate revenue. For example, Google makes a ton of money by selling its Google Maps API to various car makers.
Thank you for reading this post. Please like and subscribe.