A web API (Application Programming Interface) is a system that lets two programs talk to each other over the internet by sending and receiving data in a standard format. JSON (JavaScript Object Notation) is the most common format — a human-readable way to structure data using key-value pairs that any programming language can understand.

What is an API in plain terms?

An API is a defined set of rules that one piece of software exposes so that other software can use its services — without knowing how it works internally. Think of it like a restaurant menu: you do not need to know how the kitchen prepares a dish; you choose from the menu, place your order, and receive the result. The menu is the API — a well-defined interface between you (the client) and the kitchen (the server).

A web API uses HTTP — the same protocol your browser uses to load web pages — to carry these requests and responses across the internet. Instead of returning HTML for a browser to display, a web API typically returns structured data (usually JSON) for a program to use.

Everyday examples of web APIs in action:

App you use API it calls Data it receives
Weather app Met Office or OpenWeather API Temperature, rain forecast, wind speed
Maps app Google Maps or OS Maps API Route data, street names, traffic
Login with Google Google OAuth API User identity, email address
Payment in an app Stripe or PayPal API Payment confirmation

What is JSON and how is it structured?

JSON (JavaScript Object Notation) is a lightweight text format for representing structured data. It was designed to be easy for both humans to read and machines to parse.

JSON represents data as objects (collections of key-value pairs enclosed in {}) and arrays (ordered lists enclosed in []).

Example — a JSON object representing a student:

{
  "name": "Priya Sharma",
  "age": 14,
  "year_group": 9,
  "subjects": ["Maths", "English", "Computer Science"],
  "prefect": true
}

Key JSON rules:

Rule Example
Keys must be strings in double quotes "name"
String values use double quotes "Priya Sharma"
Numbers do not use quotes 14
Boolean values are true or false true
Arrays use square brackets ["Maths", "English"]
Objects use curly brackets {"key": "value"}
Values can be nested objects or arrays "address": {"city": "London"}

JSON is language-independent — Python, JavaScript, Java, and virtually every other language can parse and generate JSON using built-in or standard libraries.

What does an HTTP request and response look like?

When a program sends a request to a web API, it typically uses one of several HTTP methods:

Method Purpose Example
GET Retrieve data Get a list of books
POST Send new data Submit a form or create a record
PUT Replace existing data Update a user's details
DELETE Remove data Delete a record

A simple GET request to a weather API (conceptual):

GET https://api.weather-service.com/current?city=London
Headers:
  Authorization: Bearer myApiKey12345
  Accept: application/json

A typical JSON response:

{
  "city": "London",
  "temperature_c": 18,
  "condition": "Cloudy",
  "humidity_percent": 72,
  "wind_mph": 12
}

The program (the API client) reads the JSON response and uses the values — for example, displaying "18°C, Cloudy" on screen.

What is an API key and why is it used?

Many APIs require an API key — a unique string that identifies the application or developer making requests. API keys serve two purposes:

  1. Authentication: The server knows which application is making the request.
  2. Rate limiting: The server can restrict how many requests one application makes in a given period, preventing abuse.

API keys are often sent in the request header (as shown above in the Authorization field). They must be kept secret — sharing an API key publicly lets others make requests charged to your account.

How is data from an API used in a Python program?

Python's requests library makes it straightforward to call a web API and work with the returned JSON:

import requests
import json

response = requests.get("https://api.example.com/data")
data = response.json()          # Parse the JSON response
print(data["temperature_c"])    # Access a value by key

This pattern — GET request, parse JSON, access by key — is the foundation of almost all API-based programs. For a school project, you might use a public API (one that does not require a key) to retrieve live data such as exchange rates, space station location, or public transport times.

What is the difference between an API and a web page?

Feature Web page Web API
Output format HTML (for browsers to display) JSON or XML (for programs to process)
Intended consumer Human user via a browser Another program (the client application)
Purpose Display visual content Exchange structured data
Example URL https://bbc.co.uk/news https://api.example.com/news?category=tech

A single website may offer both: the main site returns HTML pages for browsers, while its API returns JSON for mobile apps and third-party developers using the same underlying data.

Frequently asked questions

Is JSON the same as a Python dictionary?

JSON and Python dictionaries look very similar and share the key-value pair concept. The key difference is that JSON is a text format — a string — while a Python dictionary is an in-memory data structure. Python's json module converts between them: json.loads(text) converts a JSON string into a Python dictionary, and json.dumps(dict) converts a Python dictionary into a JSON string.

What is the difference between a web API and a module/library?

A Python module (such as math or random) is code that runs on your computer — you import it and call its functions directly. A web API is a service running on a remote server — you send an HTTP request over the internet and receive a response. A web API can serve millions of different programs simultaneously and can be updated without clients needing to reinstall anything. A module is faster (no network involved) but only runs locally.

Can I use a web API without Python?

Yes. Any programming language that can make HTTP requests can use a web API — JavaScript, Java, C#, Ruby, and others all have HTTP libraries. You can even test a GET API directly in a web browser by typing the URL — the JSON response will appear as text. Tools such as Postman allow developers to test API requests interactively without writing any code.

What is a REST API?

REST (Representational State Transfer) is the most common design style for web APIs. A REST API uses standard HTTP methods (GET, POST, PUT, DELETE), returns stateless responses (each request contains all necessary information — the server does not remember previous requests), and uses URLs to identify resources (/users/42 identifies user 42). Nearly every public web API — weather services, social media platforms, payment processors — uses REST principles. At KS3, you do not need to know the formal REST constraints, but understanding that APIs use HTTP methods and return JSON data is the essential foundation.


Explore web technologies, APIs, and programming with Professor Turing at aitutors.me.