As a part of End to End REST Assured Tutorial , in this post We will learn about an important interface named “RequestSpecification” in Rest Assured.

RequestSpecification is an Interface whose implemented class is
RequestSpecificationImpl. This interface helps you to create request or how the request will look like.

For example:-

  • What will be the base uri of request?
  • What will be the base path of request?
  • Which type of authentication is required?
  • How the request body will be passed?
  • How to define content type?
  • How to add cookies, headers , proxy , path parameters , query parameters etc.

In short, RequestSpecification interface contains direct methods to perform above operations and there are many more. You call find all methods of RequestSpecification here. We have already used RequestSpecification interface to construct request in previous posts. Return type of many methods is RequestSpecification which helps you to write script using builder pattern.

There are two methods in RestAssured class to start creating Request specifications:-

  1. given()
  2. with()

Return type of both methods is RequestSpecification. There are no difference between above two methods. Only difference is syntactical. Example code is below:-

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

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