1.HTTP methods
Each HTTP method is a verb that states intent — GET reads, POST creates or triggers an action, PUT/PATCH update, DELETE removes — and two properties, safety and idempotency, decide whether a client or a proxy can retry a request automatically.
Key features
- Safe methods (GET, HEAD, OPTIONS) never change server state — a browser, proxy, or crawler can call them freely
- Idempotent methods (GET, PUT, DELETE, HEAD, OPTIONS) produce the same end state no matter how many times they repeat
- POST is neither safe nor idempotent by default — calling it twice can create two resources, which is why "retry a POST" is dangerous
- PUT replaces a resource ENTIRELY with the request body; PATCH applies a PARTIAL update — sending a partial body to PUT can null out omitted fields
- HEAD returns the same headers a GET would, with no body — used to check existence/size/last-modified cheaply
The seven methods
- GET, HEAD, OPTIONS — safe AND idempotent — always fine to retry
- PUT, DELETE — idempotent, not safe — retry is fine, state already changes
- POST, PATCH — neither — a blind retry can create a duplicate
Command
import httpx
client.get(url) # safe, idempotent
client.post(url, json={'name': 'x'}) # NOT idempotent -- calling twice creates two
client.put(url, json=full_resource) # idempotent -- same end state every time
client.patch(url, json={'name': 'y'}) # NOT idempotent by the spec's own definition
client.delete(url) # idempotent -- deleting twice ends the same waySafe methods never change state; idempotent methods are safe to retry — POST and PATCH are neither by default, so retry them only with a dedupe key.