2 min to read
Understanding HTTP Methods and Status Codes
A comprehensive guide to HTTP methods and their status codes
🎯 Overview
HTTP methods define how clients communicate with web servers. Let’s explore each method and their corresponding status codes.
graph TD;
A[🌐 HTTP Request Methods] --> B[🔍 GET Request];
A --> C[📝 POST Request];
A --> D[📄 HEAD Request];
B --> B1[💡 Used when typing URL in browser];
B1 --> B2[📄 GET /cat.png];
B2 --> B3[📦 200 OK \n Content-Type: image/png];
B3 --> B4[🖼️ Display Cat Image];
C --> C1[📤 Submitting a form];
C1 --> C2[📝 POST /sign_up \n Content-Type: application/json];
C2 --> C3[📦 200 OK \n Content-Type: text/html];
C3 --> C4[📄 Display Sign-up Page];
D --> D1[🔄 Similar to GET but no response body];
D1 --> D2[📄 HEAD /cat.png];
D2 --> D3[📦 200 OK \n Content-Type: image/png];
D3 --> D4[❌ No image, only headers];
%% Explanation
B -.-> E[📌 GET: Usually no request body];
C -.-> F[📌 POST: Usually sends data in request body];
E -.-> G[⚠️ GET doesn’t change server state];
F -.-> H[⚠️ POST can change server state];
🔍 HTTP Methods
📥 GET
- Used for retrieving information
- Read-only operations
- Doesn’t modify server data
📤 POST
- Creates new resources
- Sends data to server
- More secure than GET for data transmission
👀 HEAD
- Similar to GET but returns headers only
- No response body
- Efficient for metadata checks
📝 PUT
- Updates entire resource
- Creates if doesn’t exist
- Requires complete resource data
❌ DELETE
- Removes specified resource
- Usually returns empty response
- Should be used carefully
🔧 PATCH
- Partial resource modification
- More efficient than PUT
- Updates specific fields
ℹ️ OPTIONS
- Lists available methods
- Returns “Allow” header
- Used for API discovery
🔍 TRACE
- Diagnostic purposes
- Returns exact request
- Debugging tool
🔌 CONNECT
- Creates network tunnel
- Used for SSL/TLS
- Proxy connections
📊 HTTP Status Codes
🔵 1xx (Informational)
- Request received
- Processing continues
🟢 2xx (Success)
- Request succeeded
- Data received and accepted
🟡 3xx (Redirection)
- Additional action needed
- Resource moved
🔴 4xx (Client Error)
- Invalid request
- Resource not found
🟣 5xx (Server Error)
- Server failed
- Internal issues
Comments