write

HTTP PUT

Replaces the target resource entirely with the request payload, or creates it if it does not exist at the given URL. The client dictates the resource identifier, so PUT is idempotent.

PUT /path/{id} HTTP/1.1

Properties

Property Value / Meaning
Safe No - PUT modifies or creates the resource at the target URL.
Idempotent Yes - PUTting the same body N times leaves the resource in the same final state.
Cacheable No - PUT responses are not cached; caches must invalidate the URL instead.
Has body Yes - the body is the complete new representation of the resource.
Body in response Optional - often 200/204 with no body, or 201 with the created resource.

Examples

curl -X PUT -H 'Content-Type: application/json' -d '{"name":"Ada","role":"admin"}' https://api.example.com/users/42

Replace user 42 entirely with the given object.

curl -X PUT --upload-file ./config.yaml https://api.example.com/configs/prod

Upload a file as the full resource body.

curl -X PUT -H 'If-Match: "abc123"' -d '{...}' https://api.example.com/users/42

Optimistic concurrency using an ETag.

PUT /docs/readme HTTP/1.1\nHost: files.example.com\nContent-Type: text/markdown\n\n# Hello

Raw PUT creating or replacing a document.

Gotcha

PUT replaces the entire resource - fields omitted from the body are removed. Use PATCH for partial updates. Always require If-Match with ETags to avoid lost-update races.

Related methods

← All HTTP methods · HTTP status codes · HTTP headers