APIs from zero

What an API is

An API is how one program asks another for something — and gets an answer back. What that looks like, with everyday examples.

When an app on your phone shows today's weather, it didn't work the weather out itself. It asked a weather service: "What's the weather in Bengaluru?" — and the service answered: "28 °C, cloudy." The app then drew that on your screen.

The way the app asked — which address it used, what words, in what shape — is the weather service's API: its Application Programming Interface. An API is a promise a program makes: "Ask me like this, and I'll answer like that."

Programs asking programs

People use apps through screens: buttons, forms, menus. Programs use other programs through APIs: no screen, just questions and answers in an agreed format.

Almost everything you do online is a chain of these questions:

  • Paying in a shop — the shop's website asks a payment service: "Charge this card ₹1,499." The payment service answers: "Approved."
  • Signing in with Google — a site asks Google: "Is this person who they say they are?"
  • A ride app showing the car on a map — it asks its own servers every few seconds: "Where is driver 4021 now?"
  • Inside one company — the order system asks the stock system: "Do we have product 77?", and the stock system asks the warehouse system.

The program that asks is the client. The program that answers is the server (it "serves" the answer). The same program can be both: the order system is a server to the website, and a client of the stock system.

A request and a response

Each question is a request; each answer is a response. On the web, most APIs use HTTP — the same language your browser uses to fetch web pages. A request to a weather API might look like this:

GET https://api.weather.example.com/now?city=Bengaluru
Accept: application/json

and the response:

200 OK
Content-Type: application/json

{ "city": "Bengaluru", "temperature": 28, "sky": "cloudy" }

You'll learn every part of this in the next lessons. For now, notice the shape:

  • the request says what to do (GET — fetch something) and where (the address, or URL);
  • the response starts with a status (200 OK — it worked) and carries the data, here in a format called JSON.

A web page is made for people to read. An API response is made for programs to read: no colours, no layout, just the data.

Why APIs matter so much

  • Apps are built from them. A typical app calls dozens of APIs — its own and other companies'. If one breaks or slows down, the app breaks or slows down.
  • Teams work through them. The team building the website and the team building the payment system agree on an API, then work separately. The API is the contract between them.
  • Businesses connect through them. Banks, shops, airlines and governments share data through APIs instead of files and emails.

That is why testing APIs matters: when an API gives a wrong answer, or a slow one, everything built on top of it suffers — often without anyone noticing at first.

What you'll meet next

An API call is made of a few parts, and the next lessons take them one at a time:

Key takeaways

  • An API is how a program asks another program for something: a request goes from a client to a server, and a response comes back.
  • Most APIs speak HTTP, like your browser, and answer with data (usually JSON) instead of a web page.
  • Apps, teams and businesses are connected through APIs — so a broken or slow API breaks or slows everything built on it.

In the app: Sending requests · The practice API

A question these lessons don’t answer? Write to support@apitestcenter.com — we add lessons for the questions people ask.