Course map
Stage 1: Foundations
Stage 2: Data Integration
Stage 3: Building & Shipping
Stage 4: Customer Engagement
Stage 5: Specialization

Part 04 / Topic 1 of 6

HTTP in practice

Every integration speaks HTTP, and an FDE reads status codes the way a mechanic listens to an engine. The code's first digit tells you whose problem it is; a few specific codes tell you what to do next:

# examples/01_reading_http_status_codes_like_an.py
from http import HTTPStatus

for code in [200, 201, 204, 301, 400, 401, 403, 404, 409, 422, 429, 500, 502, 503, 504]:
    s = HTTPStatus(code)
    if code == 429:
        kind = "rate limited - wait for Retry-After, then retry"
    else:
        kind = {2: "success", 3: "redirect", 4: "client error - fix the request", 5: "server error - maybe retry"}[code // 100]
    print(f"{code} {s.phrase:24s} {kind}")
# 200 OK success
# 201 Created success
# 204 No Content success
# 301 Moved Permanently redirect
# 400 Bad Request client error - fix the request
# 401 Unauthorized client error - fix the request
# 403 Forbidden client error - fix the request
# 404 Not Found client error - fix the request
# 409 Conflict client error - fix the request
# 422 Unprocessable Content client error - fix the request
# 429 Too Many Requests rate limited - wait for Retry-After, then retry
# 500 Internal Server Error server error - maybe retry
# 502 Bad Gateway server error - maybe retry
# 503 Service Unavailable server error - maybe retry
# 504 Gateway Timeout server error - maybe retry

The retry rule that falls out of this table: retry 429 and 5xx (502/503/504); do not retry other 4xx โ€” the request itself is wrong, so sending it again unchanged fails again. (408, a client timeout, is the other retryable 4xx you may meet.) Part 5 builds this rule into a real client.

๐Ÿงช Quick quiz โ€” answer from memory, then check.

  1. An API returns 429. What does it mean and what should you do?
Show the answer

Too many requests: wait (respecting the Retry-After header) and retry. Part 5's resilient client does exactly this and succeeds.

  1. Which status codes should a client usually retry?
Show the answer

429 and 5xx such as 502, 503, 504. Most 4xx errors mean the request itself is wrong, so retrying it unchanged fails again โ€” 429 (and sometimes 408) are the exceptions.

Done here? The practice set for Part 4 โ€” 4 exercises with solutions โ€” is on the part page.

Search the guide