Web Development

What Is an API? A Simple Explanation With Real Examples

APIs explained in plain English: what an API is, how requests and responses work, REST and JSON, real examples from weather apps to payments, and how to try one yourself.

On this page 7 sections
  1. 01The restaurant analogy
  2. 02How an API request works
  3. 03Types of APIs
  4. 04Everyday examples
  5. 05API keys and security
  6. 06How to try an API yourself
  7. 07Frequently asked questions

Short answer: An API (Application Programming Interface) is a set of rules that lets one piece of software ask another piece of software for data or actions. Your app sends a request (for example, “give me today’s weather in Karachi”), and the other system sends back a response, usually as JSON data.

The restaurant analogy

You (the app) don’t walk into the kitchen (the server). You give your order to the waiter (the API), who brings back your food (the data). You don’t need to know how the kitchen works, only how to order.

How an API request works

  1. Endpoint: the URL you call, like https://api.example.com/weather
  2. Method: what you want to do: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)
  3. Parameters and body: extra details, like the city name
  4. Headers: extra info such as an API key for authentication
  5. Response: data back, plus a status code (200 OK, 404 Not Found, 401 Unauthorized, 500 Server Error)

A tiny example in JavaScript:

javascript
const res = await fetch("https://api.example.com/weather?city=Karachi");
const data = await res.json();
console.log(data.temperature);

And the JSON that might come back:

json
{ "city": "Karachi", "temperature": 31, "condition": "Sunny" }

Types of APIs

  • REST: the most common style for web APIs, using URLs and HTTP methods
  • GraphQL: you ask for exactly the fields you want in one query
  • Webhooks: the other system calls you when something happens (like “payment received”)
  • SDKs and libraries: code packages that wrap an API so it’s easier to use

Everyday examples

  • A weather app getting forecasts
  • “Log in with Google” buttons
  • Payment gateways processing cards
  • Google Maps embedded on a contact page
  • Courier tracking on an online store
  • AI features calling models like ChatGPT or Claude. My AI SEO plugin uses an AI API to write meta descriptions.

API keys and security

  • Keep API keys secret and on the server, never in public front-end code
  • Use HTTPS
  • Respect rate limits (how many requests you can make)
  • Validate everything that comes in and goes out

How to try an API yourself

  1. Open a free public API (weather, jokes, countries)
  2. Paste the URL in your browser and look at the JSON
  3. Call it with fetch in JavaScript or requests in Python
  4. Show the data on a simple web page

That project teaches you the core of modern web development. Next steps are in the web development roadmap.

Frequently asked questions

What does API stand for?

Application Programming Interface.

Is an API the same as a website?

No. A website is for people to read. An API is for programs to exchange data, usually in JSON.

Are APIs free?

Some are free, many have free tiers with limits, and others are paid per request.

Do I need an API for my business website?

You probably already use several: maps, forms, payments, analytics and booking tools all work through APIs. Custom integrations connect your website to your CRM, inventory or other systems.

→keep reading

You might also like