HTTP Methods Cheat Sheet (GET, POST, PUT, DELETE)
Overview
HTTP methods define the action to be performed on a resource. The four most common are GET,
POST, PUT, and DELETE.
Each one is used depending on what kind of interaction the client needs to make with the server.
GET
Use: Retrieve data (read-only)
Properties:
- Parameters appear in the URL (query string)
- Can be bookmarked or cached
- Should not modify server data
Example Scenarios:
- Viewing a product page: GET /product?id=25
- Searching inventory: GET /inventory?search=brake+fluid
POST
Use: Create a new resource or submit data
Properties:
- Parameters sent in the request body (hidden)
- Not cached or saved in browser history
- Can modify server state (e.g. database)
Example Scenarios:
- Logging in: POST /login
- Adding a new sale: POST /add_sale.php
- Uploading a file: POST /upload
PUT
Use: Update an existing resource completely
Properties:
- Similar to POST but used for full updates
- Usually sends all fields of the record
Example Scenarios:
- Updating user profile: PUT /users/7
- Replacing inventory info: PUT /inventory/123
DELETE
Use: Delete a resource
Properties:
- Often done through URL or AJAX
- Removes the target resource identified by the URL
Example Scenarios:
- Deleting a sale: DELETE /sales/45
- Removing a staff member: DELETE /staff/8
Best Practices
- Use GET for data retrieval only.
- Use POST when submitting forms or creating new data.
- Use PUT for updating full records.
- Use DELETE for removing data.
- Always validate and authorize requests on the server side.