TLDR; This is a mental model of how APIs work and a brief overview of how the internet works.
Growing up in the '90s, I often heard the internet is referred to as the "information highway." I never truly understood what that meant until I started learning about until I started creating full-stack applications. The purpose of the World Wide Web is to retrieve and send information from one device to another. A device can be a computer, cell phone, refrigerator anything that can connect to the internet. When you think about it the purpose of most apps is to organize and share information.
What is an API?
An API allows you to interact with data from an application.
That's it. That's all an API is used for.
Why use an API?
We use an API because it gives your program a level of abstraction. (Learn more about abstraction in my Object Oriented Programming article). Doing so protects your program data from users that might have malicious intentions. This also makes it easier for users to interact with your program.
Client - The computer you are using to interact with an application
Server - A computer or computer program which manages access to data
How it works:
- The client sends a request to the API server
- The API server interprets the request
- The server performs the action in the request
- The server formats the response and sends it back to the client
- The client displays the response
Think about it this way.
Let's say that Cindy is at Burger King and wants to order a whopper meal.
Cindy goes to the cashier and tells the food service worker her order. The food service worker fulfills Cindy's request and gives Cindy her meal.
In the scenario above Cindy is the "client". The food service worker is the "server" interpreting Cindy's request and checking if it can be fulfilled. The food service worker(server) responses to Cindy's(client) request by giving her food.
Now you have a high-level overview and mental model of how APIs work.