Web BasicsBasicsbeginner

What Is an API? Simple Words and Examples

APIs explained simply: the waiter analogy, a real request and response, REST basics, status codes and code to call an API.

Published
TL;DR – Quick Answer

An API (Application Programming Interface) is a set of rules that lets one program ask another program for data or actions. On the web, an app sends a request to a URL, and the server sends back a response, usually in JSON. Like a waiter, the API carries your order to the kitchen and brings back the result, without you seeing how the kitchen works.

On This Page

An API is a way for one program to ask another program for data or for an action. API stands for Application Programming Interface. The two programs agree on rules: how to ask, and what the answer will look like. On the web, a program sends a request to a URL and gets back a response, usually as JSON.

This page explains APIs with a waiter analogy, shows one real API request and response, covers REST basics and ends with short code you can run.

What is an API: the waiter analogy

You sit in a restaurant. You want food from the kitchen, but you cannot walk in and cook.

  • You read the menu. It lists what you can order.
  • You tell the waiter your order.
  • The waiter takes it to the kitchen.
  • The kitchen prepares the dish.
  • The waiter brings the dish back to you.
Restaurant API world
You The app that needs data (the client)
Menu The API documentation: what you can ask for
Waiter The API
Your order The request
Kitchen The server and its database
Dish The response

You do not need to know the recipe or who is cooking. You only need to know how to order. An API works the same way. Your app does not know how the server stores its data. It only knows what to ask for and what comes back.

API meaning for beginners: where you already use them

You use APIs many times a day without noticing:

What you do API at work
See the weather in a phone app The app asks a weather service's API for today's forecast
Log in with Google on a website The site uses Google's sign-in API
Pay with UPI on a shopping site The site talks to a payment provider's API
See a map on a food delivery app The app uses a maps API
Compare flight prices on a travel site The site asks many airlines' APIs for prices

In each case, one company's app uses data or a service that belongs to someone else, through an API.

One real API example

GitHub gives a free public API. You can ask it for details of any public GitHub user. Let us ask for octocat, GitHub's demo account.

The request

GET https://api.github.com/users/octocat

You can try this right now. Paste https://api.github.com/users/octocat into your browser's address bar. When you open a URL, your browser sends a GET request.

The response

The server replies with a status code and JSON data. Here is part of it:

{
  "login": "octocat",
  "id": 583231,
  "name": "The Octocat",
  "company": "@github",
  "location": "San Francisco",
  "public_repos": 8,
  "followers": 25505,
  "created_at": "2011-01-25T18:44:36Z"
}

Some numbers, such as followers, change over time, so you may see different values.

The status was 200 OK, which means success. Now try a user who does not exist, such as https://api.github.com/users/this-user-should-not-exist-xyz-123456. The API replies with 404 Not Found.

What is JSON

JSON (JavaScript Object Notation) is a simple text format for data. It uses "key": value pairs inside curly braces. Almost every language can read and write it, which is why most web APIs use it.

How does an API work: request and response

Every web API call has the same shape.

A request has:

Part Example Meaning
Method GET What you want to do
URL (endpoint) https://api.github.com/users/octocat What you want it done to
Headers Accept: application/json Extra details, such as format or an API key
Body {"name": "Ravi"} Data you send (used with POST, PUT, PATCH)

A response has:

Part Example Meaning
Status code 200 Did it work?
Headers Content-Type: application/json Details about the reply
Body The JSON above The data you asked for

REST API basics

Most web APIs today follow a style called REST (Representational State Transfer). In a REST API:

  • Each thing (a user, a product, an order) has its own URL, called a resource.
  • You use HTTP methods to say what you want to do with it.
  • Data usually travels as JSON.
  • Each request carries everything the server needs. The server does not remember your previous request.
Method Action Example Restaurant version
GET Read GET /students/5 "What is today's special?"
POST Create POST /students with JSON body "Place a new order"
PUT Replace PUT /students/5 with the full new data "Replace my order"
PATCH Change part PATCH /students/5 with one field "Make it less spicy"
DELETE Remove DELETE /students/5 "Cancel my order"

For a deeper guide to REST with server code, read what is REST API. The difference between the first two methods is covered in GET vs POST.

Status codes you will see most

Code Meaning
200 OK Success
201 Created A new item was created (often after POST)
400 Bad Request Your request had a mistake, such as missing data
401 Unauthorized You did not send valid login details or an API key
403 Forbidden You are known but not allowed to do this
404 Not Found No such item
429 Too Many Requests You sent too many requests too fast
500 Internal Server Error Something broke on the server

Remember: 2xx means it worked, 4xx means the client made a mistake and 5xx means the server had a problem.

Call an API with code

Both programs below ask GitHub's API for the octocat user and print three fields.

JavaScript (Node.js 18 or later)

Save as api.mjs and run node api.mjs:

const response = await fetch("https://api.github.com/users/octocat");
console.log("Status:", response.status);

const user = await response.json();
console.log("Name:", user.name);
console.log("Public repos:", user.public_repos);
console.log("Joined:", user.created_at);

Python

Save as api.py and run python api.py. It uses only the standard library:

import json
import urllib.request

url = "https://api.github.com/users/octocat"
with urllib.request.urlopen(url) as response:
    print("Status:", response.status)
    user = json.load(response)

print("Name:", user["name"])
print("Public repos:", user["public_repos"])
print("Joined:", user["created_at"])

Output of both:

Status: 200
Name: The Octocat
Public repos: 8
Joined: 2011-01-25T18:44:36Z

GitHub limits API calls made without logging in to 60 per hour from one IP address, which is plenty for learning.

Pro tip: Paste a long JSON response into a JSON formatter to see it with proper spacing. It is much easier to read than one long line.

Types of APIs

The word API is wider than web services.

Type What it connects Example
Web API Programs over the internet using HTTP GitHub API, weather APIs
Library API Your code and a library in the same program Java's ArrayList methods, Python's math module
Operating system API Programs and the operating system Opening files, reading the camera on a phone
Browser API Web page JavaScript and the browser fetch, localStorage, geolocation

When people say "API" in web development, they usually mean a web API.

API keys and security

Many APIs need an API key, a secret string that identifies your app. You send it in a header with each request. The provider uses it to:

  • Know who is calling.
  • Limit how many calls you can make.
  • Bill you, if the API is paid.
  • Block you if you misuse it.

Common mistake: Pushing code with an API key to a public GitHub repository. Anyone can copy it and use your quota or run up a bill. Keep keys in environment variables or a .env file, and add that file to .gitignore.

API vs website

Website API
Made for People Programs
Sends back HTML pages with design Data, usually JSON
You use it with A browser Code, or tools such as Postman

Many companies have both. github.com is the website for people. api.github.com is the API for programs. The page you see in a browser is often built using data from the company's own API. Read how websites work to see where the API sits in a page load.

Testing APIs

Developers and testers check APIs with tools such as:

  • Postman: send requests and see responses with a few clicks.
  • curl: a command-line tool, for example curl https://api.github.com/users/octocat.
  • Browser developer tools: press F12, open the Network tab and watch the API calls a page makes.

API testing is a common job skill for both developers and testers. The API testing interview questions show what interviewers ask.

Quick revision

  • API means Application Programming Interface.
  • It lets one program ask another for data or actions using agreed rules.
  • A web API call is a request to a URL and a response, usually JSON.
  • REST APIs use GET, POST, PUT, PATCH and DELETE on resources.
  • Status codes tell you whether the call worked.

Want to build your own API? Our Spring Boot REST API guide shows how to write one in Java.

Frequently Asked Questions

What is an API in simple words?
An API is a messenger between two programs. One program asks for something in an agreed format, and the other answers in an agreed format.
What is the full form of API?
API stands for Application Programming Interface.
What is a real-life example of an API?
When a travel site shows flights from many airlines, it gets that data from the airlines' APIs. When a shopping site lets you pay with UPI, it talks to a payment provider's API.
What is the difference between an API and a REST API?
API is the general idea of programs talking through rules. A REST API is a web API that follows the REST style: resources at URLs, HTTP methods such as GET and POST, and usually JSON data.
What is an API key?
An API key is a secret code that identifies the program calling an API. The provider uses it to control access, count usage and block misuse. Never put an API key in public code.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — Check the Java Full Stack training details

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 4 December 2026 LinkedIn
Chat with us