post thumbnail

HTTP Request Methods

Safety: No server-side changes (e.g., GET) Idempotence: Repeatable without side effects (e.g., PUT) Best Practices: Use RESTful semantics (e.g., GET /users/123) Avoid overusing POST for clarity/caching

2025-07-23

If you’ve read our previous articles on HTTP protocol fundamentals and HTTP proxies, you already grasp the basics of how HTTP works. You might recall we briefly mentioned GET and POST requests—GET retrieves data from servers, while POST sends data. But did you know HTTP includes other methods like PATCH, PUT, and OPTIONS? Let’s dive deeper into HTTP request methods.

Evolution of HTTP Methods

HTTP methods have expanded over time:

This evolution mirrors the web’s growth from static pages to dynamic platforms.


The 9 HTTP Methods Explained

Think of HTTP methods as “verbs” in client-server communication:

  1. GET
    • Safe & Idempotent
    • Fetches data (e.g., loading Instagram posts, Google searches).
    • Like asking a waiter for a menu—read-only.
  2. POST
    • Unsafe & Non-idempotent
    • Submits data (e.g., posting a tweet, placing an order).
    • Accidentally submitting twice? Might create duplicate orders!
  3. PUT
    • Idempotent
    • Fully replaces a resource (e.g., updating a social media post).
    • If the resource doesn’t exist, it’s created.
  4. PATCH
    • Non-idempotent
    • Partially updates a resource (e.g., editing a post’s text but keeping its image).
  5. DELETE
    • Idempotent
    • Removes a resource (e.g., deleting a post).
  6. HEAD
    • Safe & Idempotent
    • Retrieves metadata (e.g., file size) without the full content.
  7. OPTIONS
    • Safe & Idempotent
    • Lists supported methods for a resource (e.g., “Can I DELETE this?”).
  8. TRACE
    • Safe & Idempotent
    • Echoes the received request for debugging.
  9. CONNECT
    • Unsafe & Non-idempotent
    • Establishes secure tunnels (e.g., HTTPS proxies).

HTTP Methods in Action: Restaurant Analogy

Imagine a restaurant where you (client) interact with a waiter (server):


Safety & Idempotency

MethodSafe?Idempotent?Use Case
GETFetch data
POSTSubmit data
PUTFull update
PATCHPartial update
DELETERemove resource
HEADMetadata check
OPTIONSList allowed actions
TRACEDebugging
CONNECTSecure tunnel

Key Definitions:


Why Method Choice Matters

Using only POST for everything is like speaking a language with one verb (“do”):

TEXTPOST /api/getUser     ❌ Unclear  
POST /api/deleteUser  ❌ Confusing  

RESTful Best Practices:

TEXTGET    /api/users/123  # Fetch user  
PUT    /api/users/123  # Update full profile  
PATCH  /api/users/123  # Update email only  
DELETE /api/users/123  # Delete user  

Benefits:


Next Up: HTTP Status Codes

Now that you’ve mastered HTTP methods, stay tuned for our deep dive into status codes (e.g., 200 OK404 Not Found) to decode server responses!