Back to Tutorials

HTTP Status Codes Guide: Complete Reference for API Developers

Understanding HTTP status codes is essential for debugging APIs, handling errors, and building robust web applications. This guide covers all status code categories with practical examples.

Quick Reference

1xx
Informational
2xx
Success
3xx
Redirect
4xx
Client Error
5xx
Server Error

1xx Informational

Informational codes indicate the server received the request and is continuing to process it. These are rarely seen in typical web applications.

CodeNameDescription
100ContinueServer received request headers, client should continue sending body
101Switching ProtocolsServer agrees to switch protocol (e.g., HTTP to WebSocket)
102ProcessingServer is processing the request but no response is available yet

2xx Success

Success codes confirm the server received, understood, and accepted the request. These are the most common responses for working applications.

CodeNameDescription
200OKStandard success response. Request succeeded.
201CreatedNew resource created successfully. Common for POST requests.
202AcceptedRequest accepted for processing, but not completed yet.
204No ContentSuccess with no response body. Common for DELETE requests.
206Partial ContentServer delivered partial content (for range requests).

Best Practice: Choose the Right Success Code

  • 200 OK: General success, GET requests
  • 201 Created: POST creating new resources
  • 204 No Content: DELETE, PUT updates with no body
  • • Don't return 200 for everything - use appropriate codes

3xx Redirect

Redirect codes indicate the client needs to take additional action to complete the request, typically by following a new URL.

CodeNameDescription
301Moved PermanentlyResource moved to new URL permanently. Update your links.
302FoundResource temporarily at different URL. Use original URL for future requests.
304Not ModifiedResource unchanged since last request. Use cached version.
307Temporary RedirectTemporary redirect, preserve request method.
308Permanent RedirectPermanent redirect, preserve request method.

301 vs 302: Permanent vs Temporary

  • 301 Moved Permanently: Use when URL changes forever. SEO value transfers to new URL.
  • 302 Found: Temporary redirect. SEO value stays at original URL.
  • 304 Not Modified: Saves bandwidth - client uses cached version.

4xx Client Error

Client error codes indicate the request contained bad syntax or could not be fulfilled. The client needs to fix the request before retrying.

CodeNameDescription
400Bad RequestMalformed request syntax. Check your request format.
401UnauthorizedAuthentication required. Log in or provide credentials.
403ForbiddenServer understands request but refuses to authorize it.
404Not FoundResource doesn't exist at specified URL.
405Method Not AllowedHTTP method not supported for this resource.
408Request TimeoutServer timed out waiting for request.
409ConflictRequest conflicts with current state of resource.
410GoneResource no longer available and won't return.
413Payload Too LargeRequest body exceeds server limits.
414URI Too LongRequested URL is too long.
415Unsupported Media TypeMedia format not supported by server.
422Unprocessable EntityRequest well-formed but semantically incorrect.
429Too Many RequestsRate limit exceeded. Slow down your requests.

Most Common Client Errors

  • 400 Bad Request: Malformed JSON, missing parameters
  • 401 Unauthorized: Missing or invalid authentication token
  • 403 Forbidden: Valid auth but insufficient permissions
  • 404 Not Found: Wrong URL or resource doesn't exist
  • 429 Too Many Requests: Rate limiting - slow down your calls

5xx Server Error

Server error codes indicate the server failed to fulfill a valid request. These are often temporary issues or server-side bugs.

CodeNameDescription
500Internal Server ErrorGeneric server error. Something went wrong on the server.
501Not ImplementedServer doesn't support the requested functionality.
502Bad GatewayServer received invalid response from upstream server.
503Service UnavailableServer temporarily unavailable (overloaded or maintenance).
504Gateway TimeoutServer didn't receive timely response from upstream.

Handling Server Errors in Your App

  • 500: Generic error - check server logs for details
  • 502/503/504: Often temporary - implement retry logic
  • • Show user-friendly messages, not raw error codes
  • • Log errors with context for debugging

Best Practices for API Status Codes

1. Use Appropriate Codes

Don't return 200 for everything. Use 201 for created resources, 204 for deletions, 400 for validation errors, 404 for missing resources. This makes debugging easier.

2. Include Error Details

For error responses, include a JSON body with error type, message, and field-level details. This helps clients fix issues quickly.

{
  "error": "validation_failed",
  "message": "Invalid input data",
  "details": {
    "email": "Invalid email format",
    "age": "Must be a positive number"
  }
}

3. Distinguish 401 vs 403

401 Unauthorized: User not logged in or token invalid/expired.403 Forbidden: User logged in but lacks permission for this action. This distinction helps implement proper auth flows.

4. Handle Rate Limiting Properly

Return 429 Too Many Requests with headers indicating retry-after time. Implement exponential backoff on the client side.

Debugging HTTP Errors

Check Request Format

400 errors often mean malformed JSON or wrong parameters. Validate your request body with our JSON Validator.

Read Error Response

Don't ignore the response body. Most APIs include error details that tell you exactly what went wrong.

Server Logs

500 errors require server-side investigation. Check application logs, database connections, and server resources.

Follow Redirects

3xx codes often indicate URL changes. Check the Location header and update your API endpoints accordingly.

Try These Tools

Related Tutorials