HTTP Status Codes
Three-digit numbers that servers send to indicate the result of an HTTP request (success, error, redirect, etc.).
What are HTTP Status Codes?
HTTP status codes are three-digit numbers that tell you what happened with your web request. Did it succeed? Was there an error? Do you need to log in? The status code answers these questions.
Every time you visit a website or call an API, you get a status code back - even if you do not see it.
The Five Categories
Status codes are grouped by their first digit:
1xx - Informational: Request received, continuing process 2xx - Success: Request succeeded 3xx - Redirection: Further action needed 4xx - Client Error: You made a mistake 5xx - Server Error: Server made a mistake
Most Common Status Codes
200 OK
Everything worked! Request succeeded. This is what you want to see for successful GET requests.
201 Created
New resource created successfully. Used after POST requests when creating new records.
204 No Content
Success, but no data to return. Common for DELETE requests where you just need confirmation of deletion.
400 Bad Request
Your request was malformed or invalid. Check your request body and parameters.
401 Unauthorized
You need to log in. No authentication provided or invalid token. User needs to authenticate.
403 Forbidden
You are logged in but do not have permission. User authenticated but not authorized for this resource.
404 Not Found
The resource you requested does not exist. Check your URL and resource ID.
500 Internal Server Error
Something went wrong on the server. Not your fault. Server has a bug or encountered an unexpected condition.
Redirects (3xx)
301 Moved Permanently
Resource moved to new URL forever. Update your bookmarks and links.
302 Found (Temporary Redirect)
Resource temporarily at different URL. Original URL still valid.
304 Not Modified
Resource has not changed since last request. Use cached version for better performance.
Handling Status Codes
Check response status and handle different codes appropriately. You can check specific status codes or use response.ok for any 2xx success code.
RESTful API Status Codes
GET (retrieve data):
- 200: Success
- 404: Not found
POST (create data):
- 201: Created successfully
- 400: Invalid data
PUT/PATCH (update data):
- 200: Updated successfully
- 404: Resource not found
DELETE:
- 204: Deleted successfully
- 404: Resource not found
Setting Status Codes (Backend)
When building APIs, always return appropriate status codes. This helps clients understand what happened and handle responses correctly.
Less Common But Useful Codes
409 Conflict: Resource already exists (duplicate email or username)
429 Too Many Requests: Rate limit exceeded, slow down
503 Service Unavailable: Server temporarily down for maintenance
422 Unprocessable Entity: Syntax correct but semantically wrong
Status Code Ranges
2xx: Success - celebrate! Everything worked as expected. 3xx: Redirect - go somewhere else to find what you need. 4xx: Your fault - fix your request before trying again. 5xx: Server fault - nothing you can do except report it.
Debugging with Status Codes
Browser DevTools Network tab shows status codes with color coding:
- Green (200s): Success
- Yellow (300s): Redirects
- Red (400s, 500s): Errors
Click on any request to see full details including headers and response body.
The Bottom Line
HTTP status codes communicate what happened with your request. Learn the common ones (200, 400, 401, 404, 500) and you can debug API issues quickly.
Always check status codes when making HTTP requests. They tell you exactly what went wrong and how to fix it.