Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 3: DNS, HTTP and HTTPS

    Status Codes

    401 vs 403 is a favourite interview question: 401 — "who are you?", 403 = "I know who you are, and no."

    Chapter 5 of 134 min read

    The Plain Picture#

    Grades on a report: A means good, F means failed. But you also want to know whose fault a failure is. "You filled the form in wrong" (your problem) is very different from "our office is flooded" (their problem).

    The Real Names#

    Every response has a 3-digit status code. The first digit is the family:

    Output
      1xx  informational   "hold on"                        rare in practice
      2xx  success         "done"
      3xx  redirection     "look over there instead"
      4xx  client error    "YOU sent something wrong"       → fix the request; retrying won't help
      5xx  server error    "WE failed"                      → maybe retry later

    The ones you must know#

    CodeNameWhen
    200OKsuccess, with a body
    201Createda POST created something (return where it lives in Location)
    204No Contentsuccess, nothing to return (common for DELETE)
    301 / 308Moved Permanentlythe resource moved forever; update your links (308 keeps the method)
    302 / 307Found / Temporary Redirecttemporarily elsewhere (307 keeps the method)
    304Not Modified"your cached copy is still good" (Ch 8)
    400Bad Requestmalformed request
    401Unauthorizednot logged in — really means "unauthenticated" (Authentication and Authorization (coming soon))
    403Forbiddenlogged in, but not allowed
    404Not Foundno such resource
    405Method Not Allowede.g. DELETE on something that only allows GET
    409Conflictclashes with the current state (e.g. username taken, edit conflict)
    422Unprocessable Contentwell-formed but invalid data — FastAPI's default for validation errors
    429Too Many Requestsrate limited; slow down (see Retry-After header)
    500Internal Server Errorthe server's code crashed
    502Bad Gatewaya proxy/load balancer got a bad reply from the server behind it (Ch 12)
    503Service Unavailableoverloaded or down for maintenance
    504Gateway Timeouta proxy/load balancer gave up waiting for the server behind it

    Gotchas

    • 401 vs 403 is a favourite interview question: 401 = "who are you?", 403 = "I know who you are, and no."

    • 502 vs 504: both come from a proxy in front of your app. 502 = your app replied with garbage or reset the connection (often: it crashed or restarted). 504 = your app was too slow. Neither means the proxy is broken.

    • Returning 200 with {"error": "..."} in the body breaks every tool (monitoring, retries, caches) that relies on status codes. Use the right code.

    Check yourself

    4 questions
    1

    What do the five families (1xx–5xx) mean?

    Show answer

    Informational, success, redirection, client error, server error.

    2

    401 vs 403?

    Show answer

    401: not authenticated (who are you?). 403: authenticated but not permitted.

    3

    A user sees 504 from your load balancer. Where would you look first?

    Show answer

    At the app behind it — it's responding too slowly (slow queries, overloaded, stuck calls).

    4

    Which code for: a successful POST creating a note; a validation error in FastAPI; being rate limited?

    Show answer

    201; 422; 429.