Skip to content

HTTP Status Codes

Complete reference for HTTP response status codes.

1xx Informational Responses

CODEDESCRIPTION
100 ContinueServer received request headers
101 Switching ProtocolsSwitching to requested protocol
102 ProcessingServer processing request (WebDAV)

2xx Success

CODEDESCRIPTION
200 OKRequest succeeded
201 CreatedResource created successfully
202 AcceptedRequest accepted for processing
203 Non-Authoritative InformationModified headers from original
204 No ContentSuccess, no content returned
205 Reset ContentReset content after request
206 Partial ContentPartial GET request succeeded

3xx Redirection

CODEDESCRIPTION
300 Multiple ChoicesMultiple options available
301 Moved PermanentlyResource moved permanently
302 FoundResource moved temporarily
303 See OtherRedirect to different location
304 Not ModifiedResource not modified (ETag)
305 Use ProxyRequest via proxy
306 Switch ProxySwitch proxy (deprecated)
307 Temporary RedirectRedirect to same method
308 Permanent RedirectPermanent redirect with same method

4xx Client Errors

CODEDESCRIPTION
400 Bad RequestInvalid request syntax
401 UnauthorizedAuthentication required
402 Payment RequiredPayment required (rarely used)
403 ForbiddenAccess denied
404 Not FoundResource not found
405 Method Not AllowedMethod not allowed for resource
406 Not AcceptableNot acceptable format
407 Proxy Authentication RequiredProxy authentication needed
408 Request TimeoutClient timeout
409 ConflictConflict with current state
410 GoneResource permanently removed
411 Length RequiredContent-Length required
412 Precondition FailedPrecondition failed
413 Payload Too LargeRequest entity too large
414 URI Too LongURI too long
415 Unsupported Media TypeUnsupported media type
416 Range Not SatisfiableRequested range invalid
417 Expectation FailedExpectation failed
418 I'm a teapotApril Fools joke (HTCPCP)
422 Unprocessable EntityUnprocessable entity (WebDAV)
423 LockedResource locked (WebDAV)
424 Failed DependencyDependency failed (WebDAV)
425 Too EarlyToo early request
426 Upgrade RequiredUpgrade required
428 Precondition RequiredPrecondition required
429 Too Many RequestsRate limit exceeded
431 Request Header Fields Too LargeHeaders too large
451 Unavailable For Legal ReasonsUnavailable for legal reasons

5xx Server Errors

CODEDESCRIPTION
500 Internal Server ErrorGeneric server error
501 Not ImplementedFeature not implemented
502 Bad GatewayInvalid response from upstream
503 Service UnavailableService temporarily unavailable
504 Gateway TimeoutUpstream timeout
505 HTTP Version Not SupportedHTTP version not supported
506 Variant Also NegotiatesVariant negotiates (rare)
507 Insufficient StorageInsufficient storage (WebDAV)
508 Loop DetectedLoop detected (WebDAV)
510 Not ExtendedExtensions not supported
511 Network Authentication RequiredNetwork auth required

Common Status Codes

200 OK

The request succeeded.

Example:

bash
curl -I https://example.com
# HTTP/1.1 200 OK

301 Moved Permanently

The resource has been permanently moved to a new location.

Use Cases:

  • Changed URL structure
  • Redirecting from non-www to www
  • Protocol upgrade (HTTP to HTTPS)

Example:

bash
curl -I http://example.com
# HTTP/1.1 301 Moved Permanently
# Location: https://example.com

302 Found

The resource temporarily resides at a different location.

Use Cases:

  • Temporary redirects
  • POST-Redirect-GET pattern

Example:

bash
curl -I https://example.com/login
# HTTP/1.1 302 Found
# Location: https://example.com/dashboard

304 Not Modified

The resource has not been modified since last requested.

Use Cases:

  • Caching with ETag headers
  • Conditional requests

Example:

bash
curl -I https://example.com/resource -H "If-None-Match: etag-value"
# HTTP/1.1 304 Not Modified

400 Bad Request

The server cannot process the request due to client error.

Use Cases:

  • Invalid JSON/XML
  • Missing required parameters
  • Invalid request syntax

Example:

json
{
  "error": "Bad Request",
  "message": "Invalid JSON syntax"
}

401 Unauthorized

Authentication is required.

Use Cases:

  • Missing authentication token
  • Invalid credentials
  • Expired session

Example:

bash
curl https://api.example.com/users
# HTTP/1.1 401 Unauthorized
# WWW-Authenticate: Bearer

403 Forbidden

The server understood the request but refuses to authorize it.

Use Cases:

  • Insufficient permissions
  • IP-based restrictions
  • Geographic restrictions

Example:

bash
curl https://api.example.com/admin
# HTTP/1.1 403 Forbidden

404 Not Found

The resource could not be found.

Use Cases:

  • Invalid URL
  • Deleted resource
  • Typo in URL

Example:

bash
curl https://example.com/invalid-page
# HTTP/1.1 404 Not Found

429 Too Many Requests

The user has sent too many requests in a given time.

Use Cases:

  • Rate limiting
  • API throttling

Example:

bash
curl -I https://api.example.com/data
# HTTP/1.1 429 Too Many Requests
# Retry-After: 60

500 Internal Server Error

Unexpected error occurred on server.

Use Cases:

  • Unhandled exceptions
  • Database errors
  • Configuration errors

Example:

bash
curl https://api.example.com/error
# HTTP/1.1 500 Internal Server Error

502 Bad Gateway

The server received invalid response from upstream server.

Use Cases:

  • Upstream server down
  • Upstream server timeout
  • Invalid upstream response

Example:

bash
curl https://example.com/proxy
# HTTP/1.1 502 Bad Gateway

503 Service Unavailable

The server is temporarily unavailable.

Use Cases:

  • Server maintenance
  • Overloaded server
  • DDoS protection

Example:

bash
curl -I https://example.com
# HTTP/1.1 503 Service Unavailable
# Retry-After: 3600

504 Gateway Timeout

The server did not receive timely response from upstream.

Use Cases:

  • Upstream server slow
  • Upstream server timeout
  • Network issues

Example:

bash
curl https://example.com/slow
# HTTP/1.1 504 Gateway Timeout

HTTP Headers

Common Request Headers

HEADERDESCRIPTION
AcceptContent types acceptable
Accept-LanguagePreferred language
AuthorizationAuthentication credentials
Content-TypeMedia type of body
CookieHTTP cookies
User-AgentClient user agent

Common Response Headers

HEADERDESCRIPTION
Content-TypeMedia type of response
Content-LengthResponse body length
Set-CookieHTTP cookies
Cache-ControlCaching directives
ETagEntity tag for caching
LocationRedirect location
Retry-AfterRetry after time
WWW-AuthenticateAuthentication scheme

Curl Examples

Check Status Code

bash
# Get status code only
curl -o /dev/null -s -w "%{http_code}" https://example.com

# With redirect
curl -o /dev/null -s -w "%{http_code}" -L https://example.com

Follow Redirects

bash
curl -L https://example.com

With Custom Headers

bash
curl -H "Authorization: Bearer token" https://api.example.com

POST Request

bash
curl -X POST -H "Content-Type: application/json" \
  -d '{"key":"value"}' https://api.example.com

Upload File

bash
curl -F "file=@localfile.txt" https://example.com/upload

Best Practices

  • Use 301 for permanent redirects
  • Use 302 for temporary redirects
  • Implement proper error handling for 4xx codes
  • Log and monitor 5xx errors
  • Use appropriate status codes
  • Include proper error messages
  • Implement rate limiting (429)
  • Cache responses with 304
  • Use proper authentication (401)
  • Set proper headers
  • Monitor response times

Troubleshooting

Debug HTTP Requests

bash
# Verbose mode
curl -v https://example.com

# Show headers only
curl -I https://example.com

Check Redirect Chain

bash
# Follow all redirects
curl -L -v https://example.com 2>&1 | grep "HTTP/"

Test with Different Methods

bash
# HEAD request
curl -I https://example.com

# OPTIONS request
curl -X OPTIONS https://example.com

TIP

Use curl -v (verbose) to debug HTTP requests and see full request/response headers.

Released under MIT License.