<< Back to the PUT Request example
What is HTTP?
HTTP (Hypertext Transfer Protocol) 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 and response. Each HTTP message consists of a request line (or a status line for a response), HTTP headers, and a message body.
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 update data to the server. If the resource does not exist at the specified URI, the server should create it and return the 201 (Created) status code. If the resource is updated, 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 the data is invalid in the current context, the server should return a 501 (Not Implemented) status code.
Basic PUT Request Example
An example of sending the PUT request to the ReqBin echo URL.
What is the difference between the PUT and POST request methods?
The main difference between the PUT and POST methods is the PUT method is used when you need to update a resource, and the POST method is used when you need to add a resource. The PUT method is idempotent, which means that the client can make multiple PUT requests for the same URI without creating duplicate entries on the server, and the POST requests will change the server state after each request (may create duplicate entries). Browsers and proxy servers should not cache PUT requests.
How to send JSON data using PUT method?
To send JSON to the server, you must include the JSON data in the body of the PUT message and provide a valid Content-Type and Content-Length headers. In the example below, we make a PUT request with JSON data to the ReqBin echo URL.