Posts

Sending PUT Requests in Postman: A Step-by-Step Guide

This tutorial aims to create a PUT request in Postman and demonstrate how to execute it.

Table of Contents

What is a PUT Request?

A PUT request is an HTTP method used to update or replace a resource on a server. When a client sends a PUT request, it typically includes the updated data for the resource in the request body. The server processes this request by replacing the current representation of the resource with the new data provided by the client. If the resource does not exist, some implementations may create it.
  1. Characteristics of a PUT Request
    1. Idempotence: PUT requests are idempotent, meaning that multiple identical requests should have the same effect as a single request. For example, if you send the same PUT request multiple times, the resource's state will remain the same after the first update.
    2. Resource Identification: The URL in the PUT request specifies the resource to be updated. The server uses this URL to locate the resource and update it with the data from the request body.
    3. Full Update: PUT requests generally replace the entire resource with the data provided. A PATCH request might be more appropriate if you only want to update part of a resource.
  2. PUT Request Structure
    1. A typical PUT request includes:
      1. HTTP Method: PUT
      2. URL: The endpoint where the resource resides
      3. Headers: Metadata for the request, such as Content-Type
      4. Body: The new representation of the resource

Difference between POST and PUT

Here are some differences between POST and PUT HTTP methods:
  1. Purpose
    1. POST: Used to create a new resource or submit data to the server for processing.
    2. PUT: Used to update or replace an existing resource.
  2. Idempotence
    1. POST: Not idempotent. Multiple identical POST requests can create multiple resources.
    2. PUT: Idempotent. Multiple identical PUT requests have the same effect as a single request.
  3. Resource URI
    1. POST: The server decides the URI of the new resource.
    2. PUT: The client specifies the URI of the resource to be updated or created.
  4. Creating vs. Updating
    1. POST: Primarily used for creating resources.
    2. PUT: Primarily used for updating or completely replacing resources.
  5. Partial vs. Full Update
    1. POST: This can be used for partial updates or for operations other than resource creation.
    2. PUT: Typically replaces the entire resource with the data provided.
  6. Request Payload
    1. POST: The request payload contains the data to be processed, which may result in the creation of a new resource.
    2. PUT: The request payload contains the data to replace the existing resource.
  7. Response Status Codes
    1. POST: Common status codes include 201 (Created), 200 (OK), or 202 (Accepted).
    2. PUT: Common status codes include 200 (OK), 204 (No Content), or 201 (Created) if the resource is newly created.
  8. Server Action
    1. POST: The server processes the request payload to perform an action, such as creating a new resource or processing form data.
    2. PUT: The server updates the specified resource with the new data provided in the request payload.
  9. Cacheability
    1. POST: Responses to POST requests are generally not cacheable.
    2. PUT: Responses to PUT requests can be cacheable if indicated by the response headers.
  10. Usage in RESTful APIs
    1. POST: Often used for actions like form submissions, creating new records, and other operations where the client does not know the resource URI.
    2. PUT: Used for updating existing records where the client knows the resource URI and can replace the resource with the provided data.
Request URL
https://restful-booker.herokuapp.com/booking/bookingid
Sample Request Body
{
	"firstname": "Testing",
	"lastname": "Therapy",
	"totalprice": 2250,
	"depositpaid": true,
	"bookingdates": {
    	"checkin": "2024-05-30",
    	"checkout": "2024-06-01"
	},
	"additionalneeds": "Dinner"
}
    

Implementation Steps

Make a collection

Please follow this post to learn how to create a Collection in Postman

Make a request to the Collection

Step 1: To create a new request, click on the 3 dots and select “Add request”.

Step 2: Once you create a new request, then you will get the following window:
Uploading: 183425 of 183425 bytes uploaded.

Provide the requested information.

Step 1: Enter the “name” in the request. Here, the name is “Update Booking”.

Step 2: Enter the “URL” in the address bar. Add the "bookingid" after "booking/" in the URL. You will get this "bookingid" from the Create Booking request.


Step 3: Now, select the “PUT” request from the list of request methods.

Step 4: Add a Request Body to the Post request Steps:
Click on the Body
Check the raw option

Select the JSON

 Add a Request body

This is done to ensure that we send the request in the correct format that the server expects. The request body example mentioned at the beginning of the tutorial should be copied and pasted into the Postman request body. 

Step 5:: Press the “Send” button.

           Response

Now, it is showing that an access token is required. The HTTP status code '403 Forbidden—You don't have permission to access this resource' is displayed when a web server recognizes a user's request but cannot allow additional access.

Please follow this post to learn how to generate an access token.

Step 6:: Add 'Access Token' in this request

    Click on the 'Headers'

    Set the Query Params key as Cookie and set the Value to 'token=token value'


    Press the “Send” button.

Ensure that the Response has been validated

Format Type

Each request has a defined response to it as defined by the Content-Type header. That response can be in any format. Such as in the above example, we have a JSON code file.

Below are the various format types present in Postman.

JSON


Congratulations on finishing this tutorial and I hope you found it helpful! Happy learning!

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.