An Application Programming Interface—better known as an API—is the invisible glue that holds the modern digital world together. Whether you are checking the weather on your phone, logging into a website using your Google account, or booking a flight through a travel aggregator, APIs are working behind the scenes to make it all happen.
This guide will demystify APIs using a clear, real-world example so you can understand how they work under the hood.
What is an API? (The Restaurant Analogy)
Before diving into code or technical structures, it helps to understand the concept using a classic analogy:
- You (The Client): Sitting at a restaurant table, you want to order food. You have the menu, but you cannot walk into the kitchen and cook it yourself.
- The Kitchen (The Server): This is where all the data, logic, and preparation happen (the database or backend system).
- The Waiter (The API): The waiter takes your request (your order), walks back to the kitchen, delivers it, waits for the kitchen to prepare the meal, and brings the food back to your table.
An API is simply the messenger that takes requests from a client, tells a server what to do, and brings the response back.
A Real-World API Example: The Weather App
Let’s look at how a weather application fetches the temperature for your city using a real API request.
When you open a weather app, it doesn’t store every global weather pattern on your phone. Instead, it asks a centralized weather service (like OpenWeatherMap) for the current data.
1. The Request (Asking for Data)
To get information, your app sends an HTTP request to a specific web address called an endpoint. A typical request looks like this:
GET
[https://api.weatherservice.com/v1/current?city=Seoul&units=metric](https://api.weatherservice.com/v1/current?city=Seoul&units=metric)
GET: The method telling the server you want to retrieve information.[https://api.weatherservice.com/v1/current](https://api.weatherservice.com/v1/current): The API endpoint (the specific URL designated for current weather data).?city=Seoul&units=metric: Parameters specifying what data you want (Seoul, in Celsius).
2. The Response (Receiving the Data)
Once the server receives your request, it processes it and sends back a package of data—usually formatted in JSON (JavaScript Object Notation), which is lightweight and easy for both humans and computers to read.
The response from the weather server might look like this:
{
"city": "Seoul",
"temperature": 18.5,
"condition": "Partly Cloudy",
"humidity": 62,
"wind_speed": "3.4 m/s"
}
Once your weather app receives this JSON package, it unpacks it and displays it nicely on your screen as 18.5°C and Partly Cloudy.
Common Types of APIs You Use Every Day
APIs come in various shapes and sizes depending on how they are built and used:
- REST APIs: The most common type on the web. They use standard HTTP methods (GET, POST, PUT, DELETE) and are stateless, meaning each request is independent.
- Third-Party APIs: Services provided by external companies that developers can plug into their apps (
Leave a Reply