The HTTP PUT request method creates a new resource or replaces an existing resource on the server. In this PUT request example, we send JSON to the ReqBin echo URL. The Content-Type request header indicates the media type of the PUT request body as JSON, and the Content-Length request header indicates the size of the data in the PUT request message. The PUT request data is presented in the Content tab.
HTTP is a communication protocol between two computers and is widely used to transfer data between an HTTP client (browser or mobile app) and the server. HTTP is built around messages called request (request) and response (response). Each HTTP message consists of three parts: a request line, HTTP headers, and a message body.
Basic PUT Request Example
An example of sending a PUT request to a ReqBin echo URL.
PUT Request Example
PUT /echo/put HTTP/1.1
[put request data]
What is the PUT request method used for?
The HTTP PUT method creates or replaces the current representation of the resource on the server with new data. The PUT method is typically used to upload data to the server. If the resource does not exist at the specified URI, the server should create it and return 201 (Created) status code. If the resource has changed, the server should return a 200 (OK) or 204 (No Content) status code. The Content-Type header indicates the data type in the body of the PUT message. If the server cannot recognize the provided data or is invalid in the current context, the server should return a 501 (Not Implemented) status code.
The main difference between the POST and PUT methods is understanding the purpose of resource URIs. The POST method assumes that the content submitted by the client will be processed at the specified URI. By using PUT, the client assumes that the content being loaded matches the resource at the given URI.
PUT method is idempotent, which means that a client can make multiple PUT requests for the same URI without creating duplicate entries. The PUT method should not be cached.
Advanced PUT Request Example
In this PUT request example, we are sending JSON to the ReqBin echo URL with the correct Content-Type and Content-Length headers.