π HTTP Status Codes — The Fun, Colorful, Never-Forget Guide! π
Ever sat in an interview, scratching your head thinking… “Wait… was 302 temporary or permanent?” π€ Or maybe your API just sent you a mysterious 418 and you thought your backend was making coffee instead of returning data ☕.
Don’t worry — after this guide, HTTP status codes will stick in your brain like that catchy song you can’t stop humming π΅.
π― Why They Matter
- Interviewers love them ✅
- Debugging without them is like reading a WhatsApp chat without emojis π
- They tell you EXACTLY what's going on between client and server
π¦ Status Code Families
Think of them as big families at a wedding — each table has a theme:
- π΅ 1xx — Informational (Rare, like distant relatives π)
- π’ 2xx — Success (Happy table π)
- π‘ 3xx — Redirection (They’re moving tables π½️)
- π 4xx — Client Errors (You messed up π )
- π΄ 5xx — Server Errors (They messed up π¬)
π’ Success Codes (2xx)
- 200 OK — Everything worked! ✅
- 201 Created — New resource made π¨
- 204 No Content — Done, but nothing to show π
π‘ Redirection Codes (3xx)
- 301 Moved Permanently — URL changed forever πͺ
- 302 Found — Temporary redirect π➡️
- 304 Not Modified — Use your cache π️
π Client Error Codes (4xx)
- 400 Bad Request — Wrong request π΅
- 401 Unauthorized — You need to login π
- 403 Forbidden — You’re logged in, but NO ENTRY π·
- 404 Not Found — Page doesn’t exist π΅️♂️
- 429 Too Many Requests — Slow down! π’
π΄ Server Error Codes (5xx)
- 500 Internal Server Error — Server exploded π₯
- 502 Bad Gateway — Middleman (proxy) got bad response π‘
- 503 Service Unavailable — Server on vacation π️
- 504 Gateway Timeout — Server took too long ⏳
π§ Shortcut to Remember
1 = Info, 2 = Success, 3 = Redirect, 4 = You messed up, 5 = They messed up. Easy: "I See Really Cool Servers" π
π‘ Common Interview Questions
- What's the difference between 301 and 302? 301 = Permanent redirect, 302 = Temporary
- When would you use 204 instead of 200? When the request is successful but you have no response body.
- Why might you get 304? Client’s cache is still valid, no new data needed.
- What’s 429 and when have you seen it? Rate limiting, e.g., hitting an API too many times.
π Diagram
1xx INFO — Rare 2xx SUCCESS — Yay! 3xx REDIRECT — Go elsewhere 4xx CLIENT ERROR — Your fault 5xx SERVER ERROR — Their fault
π If-Else Style Thinking
if (statusCode < 200) info(); else if (statusCode < 300) success(); else if (statusCode < 400) redirect(); else if (statusCode < 500) clientError(); else serverError();
π¦ Amazon in Real Life — HTTP Status Codes Edition
Imagine Amazon is our web app. Here’s when each status code might happen in the real world:
- ✅ 200 OK — You search for “Noise Cancelling Headphones” and Amazon instantly shows results. Perfect!
- π― 201 Created — You place an order, and Amazon confirms: “Your order #1234 is created successfully.”
- π€· 204 No Content — You check an empty wishlist. Amazon says nothing, because... there’s nothing.
- π΅️ 301 Moved Permanently — You visit an old product link, but Amazon sends you to the updated product page.
- π 302 Found — Amazon temporarily redirects you from the homepage to a “Big Billion Sale” page.
- π 304 Not Modified — You refresh the page, but Amazon says “No change. Using your browser’s cache.”
- π« 400 Bad Request — You paste a broken URL into Amazon. Amazon has no idea what you want.
- π 401 Unauthorized — You try to view your order history without logging in. Amazon says, “Login first!”
- π· 403 Forbidden — You try to access Amazon’s admin panel. Amazon says, “Nope, not for you.”
- π 404 Not Found — You click a product that’s been deleted. Amazon can’t find it.
- ⏳ 408 Request Timeout — Your internet is too slow, and Amazon gives up waiting.
- π₯ 500 Internal Server Error — Amazon’s servers crashed. Try again later.
- π 502 Bad Gateway — Amazon’s gateway can’t get a response from a downstream service.
- π‘ 503 Service Unavailable — Amazon is under maintenance or overloaded.
- π 504 Gateway Timeout — Amazon’s payment service took too long to respond. Checkout stuck.
π Wrapping Up
Next time your API throws a weird number at you, don’t panic — just decode it like a pro π΅️. If you’ve got any personal “HTTP horror stories” from interviews or production, drop them in the comments — I might feature them in the next post!
Tags: #Java #WebDevelopment #HTTP #InterviewPrep
Comments
Post a Comment