PUT request method
The
PUT HTTP method creates a new resource or replaces a representation of the target resource with the request content.The difference between
PUT and POST is that PUT is idempotent: calling it once is no different from calling it several times successively (there are no side effects).| Request has body | Yes |
|---|---|
| Successful response has body | May |
| Safe | No |
| Idempotent | Yes |
| Cacheable | No |
| Allowed in HTML forms | No |
Syntax
<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>Optional-
An 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 following
PUT request asks to create a resource at example.com/new.html with the content <p>New File</p>:If the target resource does not have a current representation and the
PUT request successfully creates one, then the origin server must send a 201 Created response:If the target resource does have a current representation and that representation is successfully modified with the state in the request, the origin server must send either a
200 OK or a 204 No Content to indicate successful completion of the request:Specifications
| Specification |
|---|
| HTTP Semantics # PUT (external) |
Browser compatibility
The browser doesn't use the
PUT method for user-initiated actions, so "browser compatibility" doesn't apply.
Developers can set this request method using fetch().See also
- HTTP request methods
- HTTP response status codes
- HTTP headers
201 Created,204 No Contentresponse statuses

