PUT Method

PUT is a request method supported by HTTP used by the World Wide Web, used to modify and update a resource. The HTTP PUT request method is used to update existing resources with uploaded content or to create a new resource if the target resource is not found.

The difference between POST and PUT is that PUT requests are static & idempotent. Means calling the same PUT request methods multiple time will always produce the same result. It will update the same content each time while POST Request method will create new content each time.

Syntax

PUT /demo.html HTTP/1.1

Example

Request

PUT /demo.html HTTP/1.1
Host: apitier.com
Content-type: text/html
Content-length: 30

<h1>APITier</h1>
<p>Highly Scalable API Platform</p>

Response

If the target resource does not have a current representation and the PUT request successfully creates one, then the origin server must inform the user agent by sending a201 (Created) response.

HTTP/1.1 201 Created
Content-Location: /demo.html

If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server must send either a 200 (OK) or a 204 (No Content ) response to indicate successful completion of the request.

HTTP/1.1 204 No Content
Content-Location: /demo1.html

Characteristics

  • PUT requests are never cached
  • PUT requests do not remain in the browser history
  • PUT requests cannot be bookmarked

Advantages of the PUT Method

  • You can create a resource multiple times as you like.
  • Creating a resource with the PUT method is very easy.
  • It helps you to store the supplied entity under the supplied URI.
  • It can identify the entity enclosed with the request.

Click here to get more information about HTTP Status Codes