root/learning-hub/api-automation/modern-http-status-codes-reference
← Back to Learning Hub
API & AUTOMATIONCHEAT SHEET6 min readBeginner100% Client-Side Verified

Modern HTTP Status Codes & Response Headers Guide

Complete developer guide to HTTP status codes (2xx, 3xx, 4xx, 5xx) and essential security headers. Covers 401 vs 403, 429 rate limiting, and CORS headers.

#HTTP#API#REST#Status Codes#Security#Headers

Interactive HTTP Request Translator

Live Interactive Sandbox
100% Client-Side

Inspect how standard headers and POST payloads map to modern client APIs. Test the preset input below or customize it before launching into the full workspace.

Raw cURL Request:
Ready for advanced parsing, syntax error highlighting & bulk export?
Open in Full Workspace (cURL to Fetch)

HTTP status codes are the standardized three-digit communication language between client applications and web servers. Knowing precisely which status code to return in your REST, GraphQL, or RPC APIs directly impacts client error handling, browser caching, and search engine crawling.


1. The 5 Major HTTP Status Families

  • 1xx Informational: Request received, continuing process (e.g. 101 Switching Protocols for WebSockets).
  • 2xx Success: The action was successfully received, understood, and accepted.
  • 3xx Redirection: Further action must be taken to complete the request.
  • 4xx Client Error: The request contains bad syntax or cannot be fulfilled due to client fault.
  • 5xx Server Error: The server failed to fulfill an apparently valid request.

2. Essential 2xx Success Codes

Code Name Idempotent Usage
200 OK Yes Standard response for successful GET, PUT, or POST returning data.
201 Created No Successful POST that resulted in a new resource created. Should return Location header.
202 Accepted No Request accepted for asynchronous background processing (e.g. video rendering).
204 No Content Yes Successful request with no body returned (standard for DELETE or PUT).

3. Essential 3xx Redirection Codes

Code Name Search Engine Impact Usage
301 Moved Permanently Passes Link Equity Permanent redirect. Browsers aggressively cache this indefinitely.
302 Found Temporary Temporary redirect. Clients keep using original URI.
304 Not Modified Caching Optimization Client sent If-None-Match (ETag) or If-Modified-Since; use local browser cache.
307 Temporary Redirect Method Preserved Same as 302, but guarantees the HTTP Method (POST stays POST) is preserved.
308 Permanent Redirect Method Preserved Same as 301, but guarantees the HTTP Method is preserved.

4. The Critical 4xx Client Errors

401 Unauthorized vs 403 Forbidden

This is the most common confusion in modern web engineering:

  • 401 Unauthorized: The client lacks authentication. No valid token was provided. The response should include WWW-Authenticate challenge header.
  • 403 Forbidden: The client is authenticated, but lacks authorization. The server knows who the user is, but their role/permissions do not grant access.

Other High-Frequency 4xx Errors

Code Name Real-World Scenario
400 Bad Request Syntax error: Invalid JSON syntax, malformed query string.
404 Not Found Resource does not exist at requested URI.
405 Method Not Allowed Sending a POST to an endpoint that only accepts GET. Must include Allow header.
409 Conflict Optimistic concurrency conflict or duplicate database unique key (e.g. email taken).
422 Unprocessable Entity Valid JSON payload, but fails validation (e.g. Zod / Ajv validation errors).
429 Too Many Requests Rate limiting exceeded. Server must attach Retry-After: <seconds>.

5. Modern Security Headers Checklist

Every production backend and Next.js application should emit these headers:

# Prevent browsers from MIME-sniffing away from declared Content-Type
X-Content-Type-Options: nosniff

# Restrict iframe embedding to stop clickjacking attacks
X-Frame-Options: DENY

# Enforce strict HTTPS connections for 1 year including subdomains
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

# Restrict referrer information sent to third-party domains
Referrer-Policy: strict-origin-when-cross-origin

# Whitelist approved sources of executable scripts, styles, and fonts
Content-Security-Policy: default-src 'self'; img-src 'self' data: https:;

Live Tool: cURL to JavaScript Fetch

Client-Side Engine

Translate bash cURL commands into JavaScript fetch() API calls.

Launch Tool Workspace

Frequently Asked Questions (FAQ)

401 Unauthorized means 'Unauthenticated' (the client has not provided valid credentials). 403 Forbidden means 'Authenticated but Unauthorized' (the server knows who you are, but you lack permissions for this resource).