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

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

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

We will update 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. https://restful-booker.herokuapp.com/booking/1 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 body with all details. Remember it is a PUT request which takes whole body like POST request.

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 PUT request in REST Assured:-

Updated Request Body:-

I have just updated firstName and lastName.

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.
#ThanksForReading
#HappyLearning

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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply