# What is an API? Explained simply, with everyday examples

> APIs let apps talk to other software — weather, maps, payments, AI. A simple explanation of requests, responses and JSON, plus how to use APIs safely.

- URL: https://genkid.app/blog/what-is-an-api
- Topic: Under the hood
- Published: 2026-10-29 (updated 2026-11-15)
- Publisher: GenKid (https://genkid.app)

## Key takeaways

- An API (application programming interface) is a defined way for one piece of software to ask another for data or actions: a menu of what you can ask for, and the rules for asking.
- Apps send requests to an API and get responses back, often as data in a format called JSON.
- APIs let your app use other services — weather, maps, payments, AI — without building them yourself.
- Many APIs need a key to prove who's asking; keys are secrets and must stay out of front-end code.
- APIs have rules: rate limits, terms of use and sometimes costs.

## What is an API?

**An API is a menu of things a piece of software can do for other software, and the rules for asking.** The US government's Data.gov glossary puts it more formally: a set of definitions of the ways one piece of computer software communicates with another.

## The waiter analogy

Think of a restaurant. You don't walk into the kitchen and cook; you tell the waiter what you want from the menu, and the waiter brings it back. The menu is the API: it lists what you can ask for and how to ask.

Your app is the customer. The service — a weather service, for example — is the kitchen. The API is how your app places its order and gets its answer. (The same restaurant idea explains [front end vs back end](https://genkid.app/blog/front-end-vs-back-end).)

## Everyday examples

APIs are everywhere:

- A weather app asks a weather service's API for tomorrow's forecast.
- A to-do app's front end asks its own back end's API to save a task, and the back end stores it in a [database](https://genkid.app/blog/what-is-a-database).
- A map on a shop's website comes from a mapping service's API.
- An online checkout talks to a payment company's API.
- An AI coding tool sends your prompt to an AI model's API and gets code back. [AI coding agents](https://genkid.app/blog/what-is-an-ai-coding-agent) make many of these calls in a row.
- Even inside your browser, JavaScript uses built-in browser APIs to change the page or play sounds (see [HTML, CSS and JavaScript explained](https://genkid.app/blog/html-css-javascript-explained)).

## Requests and responses

Most web APIs work with **requests** and **responses**, like the [front end and back end](https://genkid.app/blog/front-end-vs-back-end) do.

Your app sends a request to an address called an **endpoint**. An API usually has several endpoints, one for each thing you can ask for — say, `/forecast` for tomorrow's weather and `/alerts` for storm warnings:

```
GET https://api.example.com/forecast?city=Wobbletown
```

The API sends back a response, often in **JSON**, a simple text format for data:

```json
{
  "city": "Wobbletown",
  "tomorrow": { "high": 18, "low": 9, "sky": "cloudy" }
}
```

Your app can then read `tomorrow.high` and show "18°" on screen.

## API keys and rules

Many APIs need to know who's asking, so they can apply limits and charge for use. That's usually done with an **API key** — a secret code. Treat it like a password:

- keep it out of front-end code (anyone can read that);
- never paste it into AI chats or screenshots;
- store it in secure settings on the server.

If you keep code on GitHub, its push protection feature can block a push that contains a secret it recognises, and for pushes to public repositories it's switched on by default for your account. It's a safety net, not a plan: keep keys out of code in the first place. See [what is an API key?](https://genkid.app/blog/api-keys-and-secrets)

APIs also have rules:

- **Rate limits** — how many requests you can make per minute or day.
- **Terms of use** — what you're allowed to do with the data, and often a minimum age to sign up.
- **Costs** — some APIs charge per request; a leaked key can run up a bill.

## When APIs go wrong

APIs depend on things outside your control. Your app should cope when:

- the service is slow or down;
- the response is missing data;
- you hit a rate limit;
- the API changes.

Good apps show a friendly message ("Couldn't load the weather — try again") instead of breaking. This is part of [testing](https://genkid.app/blog/testing-for-beginners): try what happens when the API fails.

## Worked example: when the weather API says no

Here's what a "no" can look like. Suppose your app asks for the Wobbletown forecast too many times in a minute. Instead of the forecast, the API might reply with status code **429 Too Many Requests**, which means "slow down" — the rate limit in action:

```
HTTP/1.1 429 Too Many Requests
Retry-After: 60

{ "error": "Too many requests. Try again in 60 seconds." }
```

The `Retry-After: 60` line says how many seconds to wait. Now compare two versions of the code that shows the forecast:

```js
// Version 1: assumes everything works
const data = await response.json();
message.textContent = data.tomorrow.high + "°";
```

```js
// Version 2: checks first
if (response.ok) {
  const data = await response.json();
  message.textContent = data.tomorrow.high + "°";
} else if (response.status === 429) {
  message.textContent = "Lots of people are checking the weather. Try again in a minute.";
} else {
  message.textContent = "Couldn't load the weather. Try again later.";
}
```

**Predict:** what does Version 1 show when the API sends the 429 reply? There's no `tomorrow` in the error message, so `data.tomorrow` is `undefined`, reading `.high` from it throws an error in the console, and the person using your app sees nothing at all. Version 2 checks `response.ok` (true only for a successful reply) before reading the data, so the person using your app gets a helpful message instead. When an AI writes API code for you, look for this check: it's easy to leave out, whoever writes the code.

AI coding tools sometimes invent API endpoints or options that don't exist, so always check the API's official documentation. See [why AI makes things up](https://genkid.app/blog/why-ai-makes-things-up).

## Learning APIs safely

Using real APIs often means signing up, accepting terms and managing keys — usually adult territory. GenKid teaches the ideas with a simulated API in the sandbox, so learners practise requests, responses, JSON and handling errors without accounts or keys. Real APIs come later, with an adult, as tool terms allow. See the [pathway](https://genkid.app/pathway).

## Frequently asked questions

### Is an API the same as a website?

No. A website is designed for people to read. An API is designed for programs to request data or actions, usually returning data like JSON rather than a styled page.

### Are APIs free?

Some are free, some have free limits and some charge per use. Check the terms and set limits so a mistake or leaked key can't cost a lot.

### Can kids use APIs?

Children can learn how APIs work with simulated or child-safe services. Signing up for real APIs usually requires accepting terms, often with a minimum age, so it should be an adult's decision.

## Sources

- [Glossary: API](https://resources.data.gov/glossary/api) — Data.gov, US General Services Administration
- [429 Too Many Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/429) — MDN Web Docs
- [About push protection](https://docs.github.com/en/code-security/concepts/secret-security/about-push-protection) — GitHub Docs
