What is an API?
An API (Application Programming Interface) is the agreed way for one program to ask another program for data or for an action. When you track a courier, check a PNR on IRCTC or pay through UPI, your app is not reading someone else's database directly. It sends a request to an API and receives a structured answer.
A menu, not a kitchen
An API is like a menu with a waiter. The menu lists exactly what you may ask for (the endpoints), the waiter carries your order to the kitchen (the server) and brings back a plate (the response). You never walk into the kitchen, so the restaurant can change its ovens without breaking your order.
What a request contains
A web API call is an ordinary HTTP request with four parts:
- a method saying what kind of action you want,
- a URL identifying the resource, such as
https://api.example.in/v1/invoices/4821, - headers carrying metadata such as
AuthorizationandContent-Type, - an optional body, usually JSON, holding data you are sending.
| Method | Purpose | Example |
|---|---|---|
| GET | Read data | List all invoices for March |
| POST | Create | Add a new customer |
| PUT | Replace a whole record | Overwrite a product |
| PATCH | Update a few fields | Change only the price |
| DELETE | Remove | Cancel a draft invoice |
A GET must never change anything on the server. If someone in your company builds GET /orders/12/delete, a browser
prefetch or a crawler will eventually delete an order that nobody asked to delete.
Status codes
Every response carries a three-digit status code, and the first digit tells you where the problem is.
| Code | Meaning | Typical cause |
|---|---|---|
| 200 OK | Success | A normal GET |
| 201 Created | Resource created | A successful POST |
| 400 Bad Request | Malformed data | Missing field, bad GSTIN format |
| 401 Unauthorized | No or invalid credentials | Expired token |
| 403 Forbidden | Logged in but not allowed | Sales user hitting an admin endpoint |
| 404 Not Found | Wrong URL or missing record | Typo in the invoice id |
| 429 Too Many Requests | Rate limit hit | Looping without any delay |
| 500 Server Error | Their bug | Retrying at once rarely helps |
JSON, the common language
Nearly every modern API speaks JSON: objects of key/value pairs and arrays, which map neatly onto a Python dict and list.
{
"invoice_no": "BP-2026-0481",
"customer": "Sharma Sweets, Jaipur",
"gstin": "08ABCDE1234F1Z5",
"items": [{"name": "Kaju Katli 1kg", "qty": 12, "rate": 980.0}],
"total": 11760.0,
"paid": false
}
Responses are often nested several levels deep, so read the documentation (or print one response) to learn the shape before writing parsing code. Our JSON Formatter makes a long response readable while you explore it.
Where you will meet APIs
Payment gateways (Razorpay, UPI collect), GST return filing, logistics tracking, weather and market data, maps and pin-code lookups, WhatsApp and SMS sending, and every mobile app that talks to its own backend. Internally, one API often lets your billing system, your website and your Power BI report all read the same numbers.
Key takeaways
- An API is a contract: fixed endpoints, fixed request shape, predictable responses.
- The method says what you want, the URL says on what, the body carries the data.
- Always check the status code before you touch the body.
- JSON is the default data format; learn to read nested structures.
Practice
Open https://api.github.com/repos/django/django in a browser and find the stargazers_count, forks_count
and license.name values in the JSON. Then write down, for a sweets shop billing API, which method and URL you
would use to create an invoice, fetch it back, change only its payment status, and cancel it.