HTTP methods (or verbs) are used to perform operations on resources identified by a URI. Each method has a specific purpose.
Main HTTP Methods Reference
| Method | Purpose | Idempotent (Same result if called multiple times) | Safe (No server side changes) | Example | Typical Use |
|---|---|---|---|---|---|
| GET (Read) | Retrieve data from the server. | Yes | Yes | GET /users GET /users/10 | * Get all users * Get user by id |
| POST (Create) | Create a new resource. | No | No | POST /users | * Create a new user * Submit form data |
| PUT (Update) | Update or replace an existing resource entirely. | Yes | No | PUT /users/10 | * Update user (full) * Replace user info |
| PATCH (Partial Update) | Partially update an existing resource. | Yes | No | PATCH /users/10 | * Update user (partial) * Change single field |
| DELETE (Delete) | Delete a resource from the server. | Yes | No | DELETE /users/10 | * Delete user * Remove resource |
| OPTIONS (Info) | Get information about supported methods. | Yes | Yes | OPTIONS /users | * Get allowed methods * CORS preflight |
| HEAD (Partial Headers) | Similar to GET but returns headers only (no body). | Yes | Yes | HEAD /users/10 | * Check resource existence * Get metadata |
Key Properties
Idempotent Methods
- GET, PUT, DELETE, HEAD, OPTIONS are idempotent.
- Calling them multiple times produces the same result without additional side effects.
Example:
PUT /users/10with same data 5 times results in the same user data.
Safe Methods
Methods that do not change the state on the server.
Safe Methods:
GET,HEAD,OPTIONS
Quick Comparison Matrix
| Method | Create | Read | Update | Delete | Idempotent | Safe |
|---|---|---|---|---|---|---|
| GET | – | ✓ | – | – | ✓ | ✓ |
| POST | ✓ | – | – | – | ❌ | ❌ |
| PUT | – | – | ✓ | – | ✓ | ❌ |
| PATCH | – | – | ✓ | – | ✓ | ❌ |
| DELETE | – | – | – | ✓ | ✓ | ❌ |
| OPTIONS | – | – | – | – | ✓ | ✓ |
| HEAD | – | ✓ | – | – | ✓ | ✓ |
Interview Tip
- Use the correct HTTP method for the operation.
GETshould not change data.PUTreplaces the entire resource,PATCHupdates partially.