๐ 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