DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Zaynaib (Ola) Giwa
Zaynaib (Ola) Giwa

Posted on

How do APIs work?

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.

Terminology:
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:
Alt Text
Wikimedia Commons

  1. The client sends a request to the API server
  2. The API server interprets the request
  3. The server performs the action in the request
  4. The server formats the response and sends it back to the client
  5. The client displays the response

Think about it this way.

Real-World Analogy:

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.

Top comments (7)

Collapse
 
zaynaib profile image
Zaynaib (Ola) Giwa • Edited on

Your comic reminds me of an old xcd panel hahaha xcd sandwhich

I also had a job interview where I had to go through the steps and explain how I would call out to an API. I did not do too well on the challenge. So this article was motivation to get better at understanding and explaining complex topics.

Collapse
 
abdulvahab profile image
abdulvahab

Hey Zainab,
You have done the great job. Do not disappoint by negative comments. Keep it up.

Collapse
 
zaynaib profile image
Zaynaib (Ola) Giwa

Thank you for the encouragement.

Collapse
 
iamnotstatic profile image
Abdulfatai Suleiman

Cool, but the article didn't go indepth, just basic

Collapse
 
zaynaib profile image
Zaynaib (Ola) Giwa • Edited on

Well, I did explain in the TLDR; that this was going to be a basic article. Working on more an in-depth post in the future.

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.