What is an API?
An API is a defined set of operations one program exposes for another to call. On the web that usually means HTTP endpoints that accept and return JSON.
GET /api/videos → list videos
GET /api/videos/12 → one video
POST /api/videos → create one
PUT /api/videos/12 → replace one
PATCH /api/videos/12 → update part of one
DELETE /api/videos/12 → remove oneThat shape — nouns as URLs, HTTP verbs as actions — is REST.
#The pieces of a request
Method — GET, POST, PUT, PATCH, DELETE.
URL — including a query string: ?track=python&limit=10.
Headers — metadata: Content-Type, Authorization, Accept.
Body — the payload, for POST/PUT/PATCH. Usually JSON.
#Status codes worth knowing
| 200 | OK |
| 201 | Created |
| 204 | Success, no content to return |
| 400 | Bad request — your payload was malformed |
| 401 | Not authenticated |
| 403 | Authenticated, but not allowed |
| 404 | Not found |
| 422 | Understood, but validation failed |
| 429 | Rate limited — slow down |
| 500 | The server broke |
The 4xx/5xx split matters: 4xx means you sent something wrong, 5xx means they broke. Retrying a 400 will never help; retrying a 503 might.
#Calling one
curl -H "Authorization: Bearer TOKEN" https://api.example.com/videosimport requests
r = requests.get(url, headers={"Authorization": f"Bearer {token}"}, timeout=10)
r.raise_for_status()
data = r.json()Always set a timeout. Without one, a hung server hangs your program indefinitely.
#Read the rate limits
Most APIs cap requests per minute and return 429 when you exceed it, often with a Retry-After header. Respect it, and cache responses you will need again.