About1
The PUT
HTTP method (HTTP verb)
creates a new resource or replaces a representation of the target resource with the request content.
Also known as a PUT request
.
Difference between POST
and PUT
The difference between PUT and POST
is that PUT
is idempotent
. On the other hand, successive POST
requests may
have additional effects, such as creating the same order several times. Therefore calling it once is no different from calling it several
times successively (there are no side effects).
Characteristics
Request has body | Successful response has body | Safe | Idempotent | Cacheable | Allowed in HTML forms |
---|---|---|---|---|---|
Yes | May | No | Yes | No | No |
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
Host header. 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 of key=value
pairs.
Examples
Successfully creating a resource
The following PUT
request asks to create a resource at example.com/new.html
with content <p>New File</p>
:
PUT /new.html HTTP/1.1
Host: example.com
Content-type: text/html
Content-length: 16
<p>New File</p>
If the target resource does not have a current representation and the PUT
request successfully creates on, then the origin
server must send a 201 Created
response:
HTTP/1.1 201 Created
Content-Location: /new.html
If the target does have a current representation and that representation is successfully modified with the sate in the request, the origin server must send either a 200 OK or a 204 No Content to indicate successful completion of the request:
HTTP/1.1 204 No Content
Content-Location: /existing.html
Anki
Links
References
MDN. “PUT method”. Available at: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/PUT . (Accessed: ). ↩︎