Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 12 / Topic 1 of 11

How the web works

The web is many computers talking. A client (your browser, or your Python program) sends a request. A server (a computer that waits for requests) sends back a response. The rules for this talk are called HTTP (HyperText Transfer Protocol). HTTPS is HTTP with encryption, so nobody in between can read it. Think of a restaurant: you (client) give the waiter an order (request), the kitchen (server) sends back your food (response).

URL parts

A URL is the address of something on the web.

https://shop.example.com:443/api/products?category=kitchen&max_price=500#top
└─┬─┘   └──────┬───────┘ └┬┘└─────┬─────┘ └──────────────┬───────────┘ └┬┘
scheme       host        port   path               query string        fragment
Part Meaning
scheme How to talk: http or https
host Which computer
port Which "door" on that computer (443 is the default for https, 80 for http)
path Which thing on the server
query string Extra options after ?, as key=value pairs joined with &
fragment A place inside a page, after # (only the browser uses it)

Python can split a URL for you:

from urllib.parse import parse_qs, urlparse

parts = urlparse("https://shop.example.com/api/products?category=kitchen&max_price=500")
print(parts.hostname)          # shop.example.com
print(parts.path)              # /api/products
print(parse_qs(parts.query))   # {'category': ['kitchen'], 'max_price': ['500']}

HTTP methods

The method says what you want to do.

Method Meaning Real-world example
GET Read something Show the product list
POST Create something new Place a new order
PUT Replace or update something Change your delivery address
DELETE Remove something Cancel a saved card

Status codes

Every response starts with a 3-digit status code. The first digit tells you the family.

Code Name Meaning
200 OK It worked, here is the data
201 Created Your new item was made (usual answer to POST)
204 No Content It worked, nothing to send back (common after DELETE)
301 Moved Permanently It lives at a new URL now
400 Bad Request Your request is wrong (missing or bad data)
401 Unauthorized Who are you? (missing or wrong API key)
403 Forbidden I know you, but you may not do this
404 Not Found No such thing
429 Too Many Requests Slow down, you hit the rate limit
500 Internal Server Error The server broke
503 Service Unavailable The server is busy or down, try later

Rule of thumb: 2xx = success, 3xx = go elsewhere, 4xx = your mistake, 5xx = the server's problem.

Headers and the JSON body

Headers are extra Name: value lines sent with a request or a response, like the label on a parcel. The body is the parcel itself: the actual data. Web APIs usually send the body as JSON (Part 8).

GET /api/products/1 HTTP/1.1          <- method, path
Host: shop.example.com                <- request headers
Accept: application/json

HTTP/1.1 200 OK                       <- status code
Content-Type: application/json        <- response headers

{"id": 1, "name": "Steel water bottle", "price": 450}     <- body

Full program: examples/01_url_and_http_basics.py (URL parts, urlencode, a status code table).

🔍 Going deeper: http.HTTPStatus(404).phrase gives 'Not Found'. HTTP itself has no memory between requests ("stateless"); websites remember you with cookies or tokens sent in headers.

Done here? The practice set for Part 12 — 8 exercises with solutions — is on the part page.

Search the guide