Hey there!
If you've ever built a website or played around with APIs, you've probably seen some strange numbers in your browser or response logs. Things like 200
, 404
, or even 500
. These are HTTP status codes, and they actually tell us a lot about what's happening between the client (like your browser or an app) and the server (where your website or backend lives).
In this post, I'll explain these codes using real-world examples, making them easier to understand and remember. Let's dive in!
What are HTTP Status Codes?
HTTP status codes are three-digit numbers that the server sends back to the client. They tell us whether a request was successful, failed, or needs attention.
You can think of them like traffic lights:
- Green light? All good.
- Yellow? Something needs your attention.
- Red? Something went wrong.
These codes are grouped into five categories, based on the first digit.
1xx: Informational (Just letting you know)
You won’t usually see these unless you’re deep into debugging or writing low-level networking code.
Example:
100 Continue
– The server is saying, “Cool, I got your request so far. Keep going!”
2xx: Success (Everything went fine)
These are the best kinds of responses. It means your request worked the way it should.
Examples:
200 OK
– The standard "all good" response.Example: You visit a blog post, and the content loads correctly. The server responds with
200 OK
.201 Created
– Something was successfully created.Example: You sign up on a website, and your account is created. The server replies with
201 Created
.204 No Content
– The request was successful, but there's nothing to return.Example: You delete a comment, and the server responds with
204
because there’s nothing to show back.
3xx: Redirection (Go somewhere else)
These codes mean the resource has moved or the client should take a different path.
Examples:
301 Moved Permanently
– The page has moved for good.Example: You go to
http://old-website.com
, and it redirects tohttps://new-website.com
. You get a301
.302 Found
– The page has temporarily moved.Example: Maybe you're running an A/B test and redirecting visitors to different pages. A
302
is used in that case.
4xx: Client Errors (You did something wrong)
These are usually your fault. Maybe you typed the wrong URL or tried to access something you shouldn't.
Examples:
400 Bad Request
– Your request doesn’t make sense.Example: You call an API but forget to send the required data, like
username
oremail
.401 Unauthorized
– You're not logged in or your credentials are wrong.Example: You try to access your profile without logging in.
403 Forbidden
– You're logged in, but you still can't access it.Example: You're logged in as a regular user and try to visit the admin panel.
404 Not Found
– The most famous one. It means the server can't find what you're looking for.Example: You visit
mysite.com/blog/this-page-does-not-exist
. Boom,404
.429 Too Many Requests
– You're spamming the server.Example: Your script makes 1000 API calls in one minute. The server says, “Slow down!”
5xx: Server Errors (We messed up)
These mean something went wrong on the server’s side. Not your fault.
Examples:
500 Internal Server Error
– A generic error. Something went wrong on the server, but it’s not telling you what.Example: A bug in the backend code crashes during your request.
502 Bad Gateway
– The server was acting as a gateway or proxy and got an invalid response.Example: You're using a reverse proxy like Nginx, and the backend service isn't responding properly.
503 Service Unavailable
– The server is temporarily unavailable.Example: The server is down for maintenance or too busy handling other requests.
Wrapping it Up
HTTP status codes are like quick text messages from your server. Once you get the hang of them, you’ll start to understand what’s happening just by looking at the numbers.
Here’s a quick cheat sheet:
Code Range | Meaning |
---|---|
1xx | Just information |
2xx | Success |
3xx | Redirects |
4xx | Client-side errors |
5xx | Server-side errors |
Next time you're debugging your API or wondering why your webpage isn't loading, take a look at the status code. It might just tell you exactly what's going on.
Let me know in the comments if you've seen any weird status codes in the wild. I'd love to hear your stories!
Comments
Please login to publish your comment!
By logging in, you agree to our Terms of Service and Privacy Policy.
No comments here!