Middle
What criteria do you use when choosing an HTTP method?
sobes.tech AI
Answer from AI
When choosing an HTTP method, I consider its semantics and the task of the operation:
- GET — for retrieving data without changing the server state. Safe and idempotent.
- POST — for creating new resources or performing operations that change state. Not idempotent.
- PUT — for completely updating a resource. Idempotent.
- PATCH — for partial updates to a resource. Usually not idempotent.
- DELETE — for deleting a resource. Idempotent.
Criteria for selection:
- Do I need to change the server state? If not — GET.
- Creating a new resource? — POST.
- Fully updating an existing one? — PUT.
- Partially updating? — PATCH.
- Deleting? — DELETE.
Also consider idempotency (repeating requests without changing the result), safety, and cacheability. For example, GET requests can be cached, POST — cannot.
Example: to get a list of users — GET /users, to create a new one — POST /users, to update user data — PUT /users/{id}.