Let's take a simple real-world example of an API in action.
Example: Weather API
Imagine you have a mobile app that shows the current weather. Instead of
collecting weather data itself, the app requests data from a weather service like
OpenWeather or WeatherAPI.
How It Works:
1. Your App (Client) Sends a Request
The app sends a request to the Weather API:
bash
CopyEdit
GET https://api.openweathermap.org/data/2.5/weather?
q=Bangkok&appid=YOUR_API_KEY
2. Weather API (Server) Processes the Request
The API fetches the latest weather data for Bangkok.
3. Weather API Responds with Data
The API sends back weather details in JSON format:
json
CopyEdit
{
"city": "Bangkok",
"temperature": "30°C",
"humidity": "80%",
"weather": "Cloudy"
}
4. Your App Displays the Data
The app takes this response and shows it in a user-friendly format.
This way, your app gets weather data without storing or managing it—thanks to
the API!