Make Selenium Easy

REST Assured Tutorial 11 – Let’s Write First PATCH Request in REST Assured

As a part of End to End REST Assured Tutorial , in this post We will write first PATCH request in REST assured.

I will strongly recommended you to learn basics of API testing from here.

To learn what is PATCH request and how can you hit a PATCH request in Postman tool, must refer this post.

We will update partially a booking details using “UpdateBooking” API provided by Restful Booker.

Refer Update Booking API documentation to understand how authentication and body need to be provided to request.

Below points summarize the above documentation :-

  1. We need to pass booking id for which you want to update details in URI. E.g. where “1” is booking id.
  2. Authentication token need to pass as cookie. Cookie name is “token” and value is generated auth token. ‘Cookie: token=<generatedToken>’.
  3. Pass the fields which you want to update in body with new value. Remember it is a PATCH request where you no need to pass whole body. 

Let’s see existing details of a Booking ID 1 using Postman:-

Let’s generate token which I have already covered in Previous post. Perform all above steps in Postman tool as of now. We will see in upcoming posts to chain different requests in REST Assured.

Generate Token:-

Let’s write PATCH request in REST Assured:-

Updated Request Body:-

I have just updated firstName and lastName. So in request payload, we will send only two fields unlike PUT in previous post.

REST Assured Code:-

Non-BDD Style:-

BDD Style:-

Note:- You need to generate access token every time you hit the request otherwise you will get error code as 403.

You can clone/download example repo here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

5 thoughts on “REST Assured Tutorial 11 – Let’s Write First PATCH Request in REST Assured

  1. Hi,

    How to update nested json value using patch
    for example
    “bookingdetails” :{
    “checkin” : “2021-06-19”,
    “checkout” : “2021-06-25”

    how to update values for checkin and chekout??

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

REST Assured Tutorial 11 – Let’s Write First PATCH Request in REST Assured

by Amod Mahajan time to read: 3 min
%d bloggers like this: