APIs

⏱ 7 min✏️ Quiz at the end

Introduction

Open a food delivery app and tap "order." Within seconds you see a live map of your driver, a running total, and an estimated arrival time β€” even though the app itself has no delivery drivers, no payment processor, and no mapping data of its own. It borrows all of that from other companies' software. The mechanism that makes this borrowing possible is the API, short for Application Programming Interface.

An API is a defined way for one piece of software to ask another piece of software to do something, or hand over some data, without needing to know how that other software works on the inside. It is an interface β€” a boundary with clear rules β€” much like a car's steering wheel and pedals are an interface: you do not need to understand the engine to drive.

The Waiter Analogy

Picture a restaurant. You (the customer) do not walk into the kitchen and cook your own meal. You tell a waiter what you want from a menu, the waiter carries that request to the kitchen, and the kitchen sends food back through the waiter. You never see how the kitchen works β€” only the menu (what you're allowed to ask for) and the food that arrives (the result).

An API plays the waiter's role between two programs. One program (the client) sends a request; the API defines exactly what requests are valid and what shape the response will take; the other program (the server) does the real work and sends a response back. The client never needs to see the server's internal code, database, or logic β€” just the menu of allowed requests, published as documentation.

A Concrete Example: A Weather API

Suppose a fitness app wants to warn users before a run if rain is expected. The company that built the app almost certainly does not operate weather satellites. Instead, it sends a request to a weather company's public API β€” something like "give me the forecast for this postcode" β€” and receives back a compact reply, often in a text format called JSON (JavaScript Object Notation), containing the temperature, chance of rain, and wind speed. The fitness app reads that data and displays it, all in well under a second.

This is the real power of APIs: a piece of functionality is built once, by experts, and then reused by thousands of unrelated apps. Weather, maps, payments, login-with-Google, currency conversion β€” nearly all of them reach your phone through an API someone else maintains.

Requests, Responses, and Status Codes

Most APIs on the web follow the same protocol as ordinary web pages, called HTTP. A request typically includes:

  • An endpoint β€” a web address identifying exactly what is being asked for (e.g. /forecast/london)
  • A method β€” commonly GET (fetch data), POST (send new data), PUT (update data), or DELETE (remove data)
  • Sometimes parameters β€” extra details like a date range or a search term

The server replies with a status code summarising what happened, plus data if relevant:

  • 200 β€” success, here is your data
  • 404 β€” the requested resource does not exist
  • 401 β€” you are not authorised (often means a missing or wrong API key)
  • 500 β€” something went wrong on the server's end

Recognising these codes is one of the first practical debugging skills a programmer learns when working with APIs.

Why APIs Matter

APIs let large systems stay organised. Inside a single company, different teams build separate services β€” a login service, a payments service, an order service β€” that talk to each other only through their APIs. This means each team can change its own internal code freely, as long as the API's rules stay the same; nobody else's code breaks. This idea, keeping the what stable while the how can change freely underneath, is the same principle behind abstraction elsewhere in computer science.

APIs also come with keys: a unique code identifying who is making requests, so a provider can limit how many requests a user makes per minute (rate limiting) or charge for heavy use. This connects to the wider world of online safety and encryption β€” sensitive API keys must be protected, since anyone holding one can act as that user.

Key Words

  • API (Application Programming Interface) β€” a defined way for one program to request services or data from another
  • Client β€” the program making a request
  • Server β€” the program receiving the request and sending back a response
  • Endpoint β€” a specific address identifying what is being requested
  • JSON β€” a lightweight text format commonly used to exchange data through APIs
  • Status code β€” a number summarising what happened to a request, such as 200 (success) or 404 (not found)
  • API key β€” a unique code identifying who is making a request, used for security and rate limiting