1. GET
- Purpose: Retrieve (fetch) data from the server.
- Properties:
- Parameters sent in URL query string (
?key=value).
- Visible in browser history, logs, bookmarks.
- Has length limits (depends on browser/server).
- Idempotent β doesnβt change server state.
β
Example:
GET /profile?userid=123 HTTP/1.1
Host: example.com
π Fetch profile of user 123.
2. POST
- Purpose: Submit data to the server (form submissions, login, file uploads).
- Properties:
- Parameters sent in request body (not in URL).
- More secure than GET for sensitive data (e.g., passwords).
- Not cached, not stored in browser history.
- Can send larger payloads (files, JSON, etc.).
β
Example (Login):
POST /login HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
username=alice&password=Secret123!
π This is how login forms should work.
3. PUT
- Purpose: Update or create a resource at a specific location.
- Properties:
- Replaces the entire resource (idempotent).
- Usually used in REST APIs.
β
Example:
PUT /users/123 HTTP/1.1
Host: example.com
Content-Type: application/json
{
"name": "Alice",
"email": "[email protected]"
}
π Updates user 123βs details.