Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

REST Assured Tutorial 15 – Multiple Ways of Calling HTTP Methods on a RequestSpecification

Posted on 02/19/2025 By admin

As a part of End to End REST Assured Tutorial , in this post We will learn about calling HTTP methods ( get, post, put etc) on a RequestSpecification.

We have already seen what is Request Specification in Rest Assured. The major confusing and interesting thing about Rest Assured is that you have multiple ways of performing the same action which makes beginner confused. Rest Assured is full of syntactic sugar methods.

See the example program below to understand different ways of calling http methods on RequestSpecification :-

package RestAssuredConcepts;

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

public class DifferentWaysOfCallingHttpMethodsOnRequestSpecifications {
        
        
        public static void main(String[] args) {
                
                // Creating request specification using given()
                RequestSpecification request1= RestAssured.given();
                // Setting Base URI
                request1.baseUri("https://restful-booker.herokuapp.com");
                // Setting Base Path
                request1.basePath("/booking");
                
                
                // We can directly call http verbs on RequestSpecification
                Response res1= request1.get();
                System.out.println(res1.asString());
                
                // We can also pass RequestSpecification reference variable in overloaded given() method
                Response res2 = RestAssured.given(request1).get();
                System.out.println(res2.asString());
                
                // We can also pass RequestSpecification using spec() method
                Response res3 = RestAssured.given().spec(request1).get();
                System.out.println(res3.asString());
                
        
        }

}

Output:-

[{"bookingid":13},{"bookingid":5},{"bookingid":11},{"bookingid":10},{"bookingid":8},{"bookingid":4},{"bookingid":3},{"bookingid":1},{"bookingid":6},{"bookingid":7},{"bookingid":9},{"bookingid":2},{"bookingid":12}]
[{"bookingid":13},{"bookingid":5},{"bookingid":11},{"bookingid":10},{"bookingid":8},{"bookingid":4},{"bookingid":3},{"bookingid":1},{"bookingid":6},{"bookingid":7},{"bookingid":9},{"bookingid":2},{"bookingid":12}]
[{"bookingid":13},{"bookingid":5},{"bookingid":11},{"bookingid":10},{"bookingid":8},{"bookingid":4},{"bookingid":3},{"bookingid":1},{"bookingid":6},{"bookingid":7},{"bookingid":9},{"bookingid":2},{"bookingid":12}]

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: Postman Tutorial Part 4 – Sending GET Request With Query Params in Postman
Next Post: Postman Tutorial Part 32 – Retrieve Query Parameter Value in Tests Script in Postman

Related Posts

Accessibility Testing in Slides Uncategorized
Amod Mahajan Uncategorized
Storing Web Table With Pagination Data Into List Of Map – Java Uncategorized
August 22, 2018 – Make Selenium Easy Uncategorized
April 14, 2019 – Make Selenium Easy Uncategorized
May 5, 2018 – Make Selenium Easy 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