Postman - PUT Requests



A Postman PUT request is used to pass data to the server for creation or modification of a resource. The difference between POST and PUT is that POST request is not idempotent.

This means invoking the same PUT request numerous times will always yield the same output. But invoking the same POST request numerous times will create the similar resource more than one time.

Before creating a PUT request, we shall first send a GET request to the server on an endpoint − http://dummy.restapiexample.com/api/v1/employees. The details on how to create a GET request is explained in detail in the Chapter – Postman GET Requests.

On applying the GET method, the Response body obtained is as follows −

PUT request

Now, let us update the employee_salary and employee_age for the id 21 with the help of the PUT request.

Create a PUT Request

Follow the steps given below to create a PUT request in Postman successfully −

Step 1 − Click on the New menu from the Postman application. The Create New pop-up comes up. Then, click on the Request link.

PUT Request

Step 2SAVE REQUEST pop-up comes up. Enter the Request name then click on Save.

Save Request2

Step 3 − The Request name (Test1) gets reflected on the Request tab. We shall select the option PUT from the HTTP request dropdown..

Then enter the URL - http://dummy.restapiexample.com/api/v1/update/21 (endpoint for updating the record of id 21) in the address bar.

It must be noted that in a PUT request, we have to mention the id of the resource in the server which we want to update in the URL.

For example, in the above URL we have added the id 21.

PUT request2

Step 4 − Move to the Body tab below the address bar and select the option raw.

Body Tab1

Step 5 − Then, choose JSON from the Text dropdown.

Text dropdown

Step 6 − Copy and paste the below information in the Postman Body tab.

{ "name": "Jenette Caldwell","salary": "2000","age": "15"}

The overall parameters to be set for a PUT request are shown below −

parameters

Step 7 − Click on the Send button.

Response

Once a request has been sent, we can see the response code 200 OK populated in the Response body. This signifies a successful request and the request we have sent has been accepted by the server.

Also, information on the time consumed to complete the request (673 ms) and payload size (705 B) are populated. The Response body shows the salary and age got updated to 2000 and 15 respectively for the employee having id 21.

Response3
Advertisements