What Is an API? HTTP Fundamentals
Lesson 1 of 5 · View course roadmap
Learn the idea
An API (Application Programming Interface) is a contract that lets programs talk to each other. Web APIs speak HTTP — the same protocol as your browser.
Every HTTP exchange is a request and a response:
- Methods (verbs):
GETread,POSTcreate,PUT/PATCHupdate,DELETEremove - URL:
https://api.site.com/users/42?active=true— path identifies the resource, query params filter - Status codes:
200OK,201Created,404Not Found,400Bad Request,401Unauthorized,500Server Error - Body: usually JSON data
Memory aid for status codes: 2xx = success, 3xx = redirect, 4xx = your mistake, 5xx = their mistake.
Where you'll use this
Your weather app, your bank app, 'Sign in with Google', every checkout — all API calls with these exact verbs and status codes. Backend engineering interviews open with precisely this material.
Common mistakes
- Using GET for actions that change data — GETs get cached, prefetched and retried by infrastructure; mutations belong in POST/PUT/DELETE.
- Treating all non-200s the same: a 404 (ask differently) needs different handling than a 500 (their outage) or 429 (slow down).
- Putting secrets in URLs — URLs land in server logs and browser history; secrets go in headers.
Pro tip
Learn the memorable codes cold: 200 OK, 201 Created, 301 Moved, 400 your request is malformed, 401 who are you, 403 you can't, 404 not found, 429 too fast, 500 their bug, 503 they're down.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +25 XP
The starter has a list of (method, status) tuples from an API log. Print how many were successful (status 200–299) and how many were client errors (400–499).
3 2
Count with: 200 <= status <= 299. Python lets you chain comparisons.
log = [("GET", 200), ("POST", 201), ("GET", 404), ("DELETE", 500), ("PUT", 400), ("GET", 200)]
ok = sum(1 for m, s in log if 200 <= s <= 299)
client_err = sum(1 for m, s in log if 400 <= s <= 499)
print(ok)
print(client_err)
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.