5 min read
ā¢Question 2 of 28easyWhat are HTTP Status Codes?
Understanding HTTP response status codes.
What You'll Learn
- Status code categories
- Common status codes
- When to use each
Status Code Categories
| Range | Category |
|---|---|
| 1xx | Informational |
| 2xx | Success |
| 3xx | Redirection |
| 4xx | Client Error |
| 5xx | Server Error |
Common Status Codes
Success (2xx)
- 200 OK - Request succeeded
- 201 Created - Resource created
- 204 No Content - Success, no body
Client Errors (4xx)
- 400 Bad Request - Invalid syntax
- 401 Unauthorized - Authentication required
- 403 Forbidden - No permission
- 404 Not Found - Resource doesn't exist
- 422 Unprocessable Entity - Validation failed
Server Errors (5xx)
- 500 Internal Server Error - Generic server error
- 502 Bad Gateway - Invalid upstream response
- 503 Service Unavailable - Server overloaded
Example Usage
code.jsJavaScript
// Express.js examples
res.status(200).json({ data: users });
res.status(201).json({ id: newUser.id });
res.status(404).json({ error: 'User not found' });
res.status(500).json({ error: 'Internal server error' });