API fundamentals
Is an API just a JSON?
No. An API lets your application request information or actions from another service. JSON is one way to write the data they exchange. Seeing JSON in an API response can make the two seem like the same thing, but they have different roles.
Imagine a travel app displaying the weather in Paris. It does not collect weather readings itself. It asks an external weather service through its API. That service might reply with JSON containing a city name, a temperature, and a unit such as Celsius.
The app reads those values and displays “Paris: 18 °C.” The API defines how the app can ask the weather service and what replies to expect. JSON is the format used for the data in this example. Here is the exchange, step by step.
Your travel app does not measure the temperature. It asks a separate weather service through that service’s API.
You choose a city in your travel app
Your travel app · ParisCheck weatherThis is the screen you see. You do not type any code.
The app contacts an external weather service
The weather service publishes instructions for requesting its data. Your app follows those API instructions and sends:
GET https://weatherapiexample.com/weather?city=Paris- GET
- means “retrieve information”.
- https://weatherapiexample.com
- is the external weather service’s address in this fictional example.
- /weather
- selects the weather information.
- ?city=Paris
- specifies which city to look up.
The request goes to the weather service’s server, a different system from your travel app.
The weather service returns JSON
{ "city": "Paris", "temperature": 18, "unit": "°C" }- “city”: “Paris”
- tells the app which city this is about.
- “temperature”: 18
- gives the temperature. “unit”: “°C” tells us it is in Celsius.
JSON writes information as labels and values. The labels tell the app what each value means.
Your travel app displays the weather
Paris · 18 °C
Weather from an external service
You see a weather card. Your app used data supplied by another service and chose how to display it.
The API is how your app knows what it can ask the weather service for and how to exchange information with it.
JSON is how the weather data is written in this example. It is just the data format, not the whole API.
Illustrative example. The URL is fictional and the sample data is simplified; 18 °C is not a live weather reading.