PUT request method
ThePUT HTTP method creates a new resource or replaces a representation of the target resource with the requestcontent.
The difference betweenPUT andPOST is thatPUT isidempotent: calling it once is no different from calling it several times successively (there are noside effects).
| Request has body | Yes |
|---|---|
| Successful response has body | May |
| Safe | No |
| Idempotent | Yes |
| Cacheable | No |
| Allowed inHTML forms | No |
In this article
Syntax
PUT <request-target>["?"<query>] HTTP/1.1<request-target>Identifies the target resource of the request when combined with the information provided in the
Hostheader.This is an absolute path (e.g.,/path/to/file.html) in requests to an origin server, and an absolute URL in requests to proxies (e.g.,http://www.example.com/path/to/file.html).<query>OptionalAn optional query component preceded by a question-mark
?.Often used to carry identifying information in the form ofkey=valuepairs.
Examples
>Successfully creating a resource
The followingPUT request asks to create a resource atexample.com/new.html with the content<p>New File</p>:
PUT /new.html HTTP/1.1Host: example.comContent-type: text/htmlContent-length: 16<p>New File</p>If the target resourcedoes not have a current representation and thePUT request successfully creates one, then the origin server must send a201 Created response:
HTTP/1.1 201 CreatedContent-Location: /new.htmlIf the target resourcedoes have a current representation and that representation is successfully modified with the state in the request, the origin server must send either a200 OK or a204 No Content to indicate successful completion of the request:
HTTP/1.1 204 No ContentContent-Location: /existing.htmlSpecifications
| Specification |
|---|
| HTTP Semantics> # PUT> |
Browser compatibility
The browser doesn't use thePUT method for user-initiated actions, so "browser compatibility" doesn't apply.Developers can set this request method usingfetch().