Understanding APIs (Part 2): API Analogies and Examples
Learn about some analogies and real-life examples of APIs to understand them better, including a restaurant, a calculator, and a Human Resources (HR) API using CSV and JSON data types.
Understanding APIs· Part 2 of 6
- 1.Understanding APIs (Part 1): What is an API?
- 2.Understanding APIs (Part 2): API Analogies and Examples
- 3.Understanding APIs (Part 3): What are HTTP Methods?
- 4.Understanding APIs (Part 4): What is a URI?
- 5.Understanding APIs (Part 5): Intro to Postman and Query Parameters
- 6.Understanding APIs (Part 6): What are HTTP Status Codes?
In Part 1 of this series, “Understanding APIs (Part 1): What is an API?,” we learned about the acronym, the definition, the four aspects of an API, and how everything works together. We also defined this cute little diagram below. If you feel like you forgot some pieces, you can always go back and read the recap at the end for a quick summary.

When I started learning what an API was, it took me some time to really start understanding this concept. It can become so abstract! When I look at practical examples of applied technologies, it can really open my eyes to understanding a theory. In the case of APIs, looking at different examples helped me get a better idea of this concept.
This post will complement what you learned in Part 1. You will learn about some analogies and real-life examples of APIs to understand better what they are.
API Analogies
Before I begin, I just want to get something clear: when you are using or consuming an API, you don’t really care about how the Implementation works. It doesn’t matter if the Implementation is built on Java, Python, or MuleSoft; it’s still going to give you the Response that you are expecting according to your Request.
You don’t care about what systems the API needs to call, if any, or if the API is using JSON or CSV as the internal Data Type. None of this is really visible to you anyways. You just want your Request to be processed and your Response to be returned.
1. Restaurant
Imagine you arrive at a restaurant. You sit in a chair and start looking at the menu. Then the server comes to ask for your order. You say that you want a hamburger because it was one of the choices that you selected from the menu. The employee goes to the kitchen, and someone cooks your meal. Sometime later, the server comes back with your hamburger.
“How is this an analogy for an API?”
You, the client, give a Request to the server: you want to receive a hamburger. The server does whatever needs to be done to deliver the order.
Then, you receive a Response with what you asked for: a hamburger.

Notice how I didn’t add the part of the server going to the kitchen, or the chef cooking your meal. This is because we only care about what our order was and what was delivered to us.
2. Calculator
Now, let’s say that a regular calculator is an API. You send a “2+2” Operation as a Request, hit the equal button, and receive a “4” as a Response.

Once more, you’re not interested in how the calculator processed this information; you just want an accurate response to the Inputs and Operation that you sent in the Request.
Quiz: What would be the Data Types in the RQ and RS in this scenario?
The answer will be revealed in the next post.
API Examples
Now let’s see some examples of how APIs can be used in real-life scenarios.
1. Human Resources API
You started by being a customer at a restaurant, then a calculator user, and now you are the head of the Human Resources (HR) department at FictionalCorp. Hooray!
As the HR head manager, you obviously know how to use the HR API to process the company’s information regarding the employees. You want to check what the employees’ first day of employment at FictionalCorp was, and you already know that the HR API accepts Requests in the format of a CSV file. Your Request would look like this:

There’s a CSV Data Type, the Input information of the two employees (we’re a startup, ok?), and the Operation telling the API what to do with this data. You click “Send,” and off it goes!
Within seconds the API returns the Response with the information you requested:

It returns the same Data Type (CSV format) and an Output file that contains the same information you sent in the Request, PLUS, a new field called “First Day,” which contains each of the employees’ first day of employment at FictionalCorp.
You may not know if the API is connected to a Database or to an external system where this information is kept, but it returned what you requested in the first place, which is all you need.
What would happen if the RQ/RS was in a different format, you say? Well, this HR API also accepts the JSON Data Type. Here’s how that would look:

We have the same Inputs, same Operation, and same Output, but the Data Types for both the Request and the Response are different.
2. Real-life APIs
Do you want to see some actual APIs? Follow these links to see their documentation:
It’s ok if you don’t understand everything that you see in these pages. This is just to give you an idea of what real APIs look like.
Recap
To recap, when you’re calling or consuming an API, you don’t really care about how the Implementation works; you just want your Request to be processed and a Response to be returned according to the Inputs and Operations that you sent in the RQ.
Stay tuned for Part 3 of this series if you want to know the answer to the quiz in the second analogy: the calculator. The question was: What would be the Data Types for the RQ and RS in this scenario?
I hope you are starting to get a better picture of what APIs are. Contact me or leave me some comments if you have any additional questions - I’m happy to help.
Keep learning and don’t give up!
Prost!
-Alex
FAQs
Frequently asked questions about this post.
-
How is a restaurant an analogy for an API?
You, the client, give a Request to the server: you want a hamburger that you picked from the menu. The server does whatever needs to be done to deliver the order, and then you receive a Response with what you asked for, the hamburger. We leave out the part where the server goes to the kitchen and the chef cooks the meal, because we only care about what the order was and what was delivered, not how it was made.
-
How does the calculator example map to an API?
If you treat a regular calculator as an API, you send a "2+2" Operation as a Request, hit the equal button, and receive a "4" as a Response. You are not interested in how the calculator processed the information; you just want an accurate Response to the Inputs and Operation you sent in the Request.
-
Why don't you care how an API's Implementation works when consuming it?
When you are consuming an API it does not matter whether the Implementation is built on Java, Python, or MuleSoft, nor whether it uses JSON or CSV internally, nor what systems it needs to call, because none of that is visible to you. You just want your Request to be processed and your Response returned according to the Inputs and Operations you sent.
-
What data types can the Human Resources API in the example accept?
The HR API at FictionalCorp accepts Requests in CSV format, where the Request carries the CSV Data Type, the Input information for the two employees, and the Operation telling the API what to do; the Response comes back in the same CSV format with a new "First Day" field added. The same HR API also accepts the JSON Data Type, with the same Inputs, same Operation, and same Output but different Data Types for the Request and Response.
-
Where can I see what real APIs look like?
The post links to the documentation for the Twitter API at https://developer.twitter.com/ , the Slack API at https://api.slack.com/ , the Google Maps API at https://developers.google.com/maps/documentation , and Facebook APIs at https://developers.facebook.com/ . It is fine if you do not understand everything you see; the links are just to give you an idea of what real APIs look like.
More from this series
Understanding APIs· Part 2 of 6
- 1.Understanding APIs (Part 1): What is an API?
- 2.Understanding APIs (Part 2): API Analogies and Examples
- 3.Understanding APIs (Part 3): What are HTTP Methods?
- 4.Understanding APIs (Part 4): What is a URI?
- 5.Understanding APIs (Part 5): Intro to Postman and Query Parameters
- 6.Understanding APIs (Part 6): What are HTTP Status Codes?