Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

What Is an API? HTTP Fundamentals

12 min 25 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 1 of 5 · View course roadmap
Step 1

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): GET read, POST create, PUT/PATCH update, DELETE remove
  • URL: https://api.site.com/users/42?active=true — path identifies the resource, query params filter
  • Status codes: 200 OK, 201 Created, 404 Not Found, 400 Bad Request, 401 Unauthorized, 500 Server 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.

Step 2

Try it yourself

Blank · autosaved

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”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +25 XP

Blank · autosaved

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).

Target output
3
2
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. Which HTTP method creates a new resource?
2. A 404 status means…
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path