Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

REST Assured Tutorial 12 – Let’s Write First DELETE Request in REST Assured

Posted on 02/08/2025 By admin

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

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

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

We will delete a booking details using “DeleteBooking” API provided by Restful Booker. Once deleted, we will verify it using GetBooking API.

Refer Delete 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 which you want to delete 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=’.
  3. You don’t required to pass body to DELETE 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 DELETE request in REST Assured:-

package RestfulBooker.deleteExamples;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;

public class NonBDDDeleteRequest {

        public static void main(String[] args) {

                // Create a request specification
                RequestSpecification request = RestAssured.given();

                // Setting a cookie for authentication as per API documentation
                request.cookie("token", "f4e70e7b9bbcd05");
                // Adding URI
                request.baseUri("https://restful-booker.herokuapp.com/booking/1");
                

                // Calling PUT method on URI. After hitting we get Response
                Response response = request.delete();

                // Printing Response as string
                System.out.println(response.asString());

                // Get Validatable response to perform validation
                ValidatableResponse validatableResponse = response.then();

                // Validate status code as 201 as per API documentation
                validatableResponse.statusCode(201);

                // Validate if booking is actually deleted. 
                RequestSpecification getRequestSpec = RestAssured.given();
                
                // Adding URI
                getRequestSpec.baseUri("https://restful-booker.herokuapp.com/booking/1");
                
                // Calling GET request
                Response res = getRequestSpec.get();
                
                // Get Validatable response to perform validation
                ValidatableResponse valRes = res.then();
                
                // It will check if status code is 404 as booking id should not be found
                valRes.statusCode(404);
                

        }
}

package RestfulBooker.deleteExamples;

import io.restassured.RestAssured;

public class BDDStyleDeleteRequest {

        public static void main(String[] args) {
                

                // Delete Booking

                //GIVEN
                RestAssured
                        .given()
                                        .baseUri("https://restful-booker.herokuapp.com/booking/1")
                                        .cookie("token", "f7dddb1093eab19")
                        // WHEN
                        .when()
                                        .delete()
                        // THEN
                        .then()
                                        .assertThat()
                                        .statusCode(201);
                
                // Verifying booking is deleted
                // Given
                RestAssured
                    .given()
                                    .baseUri("https://restful-booker.herokuapp.com/booking/1")
                // When
                        .when()
                                        .get()
                // Then
                        .then()
                                        .statusCode(404);

        }
}

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

Uncategorized

Post navigation

Previous Post: All about WebDriver: Methods And Its Usages
Next Post: Interview Experience At Morgan Stanley Mumbai For SDET – Sep – 2020

Related Posts

October 10, 2019 – Make Selenium Easy Uncategorized
FileUpload – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
TestNG Tutorials 29: Grouping Configuration Methods in TestNG Uncategorized
Frequently Asked Java Program 11: Find Position Of Letter In Alphabet Uncategorized
Make Selenium Easy – Page 17 Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark