| name | http-status-guide |
| description | Explain HTTP status codes with examples and best practices. Use when working with APIs, debugging HTTP responses, or learning about REST API design and HTTP protocol. |
HTTP Status Code Guide
This skill helps you understand and use HTTP status codes correctly in API development and debugging. Demonstrates the use of reference files for detailed information.
When to Use This Skill
Use this skill when:
- Debugging API responses
- Designing REST API endpoints
- Learning about HTTP protocol
- Choosing appropriate status codes for different scenarios
- Troubleshooting web applications
Core Concepts
HTTP status codes are three-digit codes that indicate the result of an HTTP request. They are grouped into five categories:
- 1xx (Informational): Request received, continuing process
- 2xx (Success): Request successfully received, understood, and accepted
- 3xx (Redirection): Further action needed to complete the request
- 4xx (Client Error): Request contains bad syntax or cannot be fulfilled
- 5xx (Server Error): Server failed to fulfill a valid request
Quick Reference
For detailed information about all status codes, see reference.md.
Most Common Status Codes
Success:
200 OK: Standard success response201 Created: Resource successfully created204 No Content: Success with no response body
Client Errors:
400 Bad Request: Invalid request syntax401 Unauthorized: Authentication required403 Forbidden: Server refuses to authorize404 Not Found: Resource doesn't exist
Server Errors:
500 Internal Server Error: Generic server error503 Service Unavailable: Server temporarily unavailable
Instructions
When helping with HTTP status codes:
- Identify the scenario: Understand what the API endpoint does
- Choose appropriate code: Select the most specific applicable code
- Provide example: Show how to use it in context
- Explain reasoning: Clarify why this code is appropriate
Examples
Example 1: Creating a New User
// POST /api/users
app.post('/api/users', async (req, res) => {
try {
const user = await createUser(req.body);
// Use 201 Created for successful resource creation
res.status(201).json({
id: user.id,
message: 'User created successfully'
});
} catch (error) {
// Use 400 Bad Request for validation errors
res.status(400).json({
error: 'Invalid user data',
details: error.message
});
}
});
Example 2: Authentication Error
// GET /api/protected-resource
app.get('/api/protected-resource', async (req, res) => {
const token = req.headers.authorization;
if (!token) {
// Use 401 Unauthorized when authentication is required
return res.status(401).json({
error: 'Authentication required',
message: 'Please provide a valid token'
});
}
// Process authenticated request...
});
Best Practices
- Use the most specific status code that applies
- Always include a response body with error details
- Be consistent across your API
- Follow RESTful conventions
- Document your API's status code usage
See reference.md for comprehensive best practices.
AI Assistant Instructions
When this skill is activated:
- Analyze the scenario: Understand what the user is trying to accomplish
- Recommend status code: Choose the most appropriate code
- Provide code example: Show implementation in their language/framework
- Explain alternatives: Discuss other codes that might apply
- Reference documentation: Point to reference.md for deeper information
Always:
- Explain why a particular status code is appropriate
- Provide working code examples
- Consider the full context (REST conventions, API design)
- Suggest response body structure
Never:
- Recommend generic codes when specific ones apply
- Use 200 OK for errors
- Ignore the semantic meaning of status codes