HTTP methods define the action to be performed on a resource. Here's a breakdown of common methods:
GET 📁
- Purpose: Retrieve resource data
- Characteristics: Safe (no side effects), Idempotent (same result on repeated requests)
- Example:
GET /resource HTTP/1.1
- Status Codes: 200 (OK), 301 (Moved Permanently), 404 (Not Found)
POST 📝
- Purpose: Submit data to the server
- Characteristics: Not safe, Not idempotent
- Example:
POST /submit-form HTTP/1.1
- Status Codes: 201 (Created), 204 (No Content), 400 (Bad Request)
PUT 🛠️
- Purpose: Update existing resource
- Characteristics: Idempotent, Not safe
- Example:
PUT /update-user HTTP/1.1
- Status Codes: 200 (OK), 204 (No Content), 400 (Bad Request)
DELETE 🧹
- Purpose: Remove resource
- Characteristics: Idempotent, Not safe
- Example:
DELETE /delete-article HTTP/1.1
- Status Codes: 200 (OK), 204 (No Content), 404 (Not Found)
PATCH 📌
- Purpose: Apply partial updates
- Characteristics: Not idempotent, Not safe
- Example:
PATCH /modify-profile HTTP/1.1
- Status Codes: 200 (OK), 204 (No Content), 400 (Bad Request)
HEAD 🧐
- Purpose: Retrieve headers only
- Characteristics: Safe, Idempotent
- Example:
HEAD /resource HTTP/1.1
- Status Codes: 200 (OK), 404 (Not Found)
OPTIONS 📚
- Purpose: Describe communication options
- Characteristics: Safe, Idempotent
- Example:
OPTIONS /api-endpoint HTTP/1.1
- Status Codes: 200 (OK), 405 (Method Not Allowed)
TRACE 🧭
- Purpose: Echo the request for debugging
- Characteristics: Safe, Not idempotent
- Example:
TRACE /debug-path HTTP/1.1
- Status Codes: 200 (OK), 405 (Method Not Allowed)
CONNECT 🔗
- Purpose: Establish a tunnel to the server
- Characteristics: Safe, Not idempotent
- Example:
CONNECT example.com:443 HTTP/1.1
- Status Codes: 200 (OK), 400 (Bad Request)
For more practical examples, visit our HTTP Methods Tutorial.