Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Class RequestSpecBuilder
Example Program
Frequently Asked Questions
Are REST assured and REST API the same?
What is the difference between Postman and REST assured?
What is REST API in testing?
Is REST assured open-source?
What type of testing is done with REST assured?
Last Updated: Mar 27, 2024

REST Assured – Building RequestSpecification Using RequestSpecBuilder

Author soham Medewar
0 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


rest assured

REST Assured is a library in Java. It provides a domain-specific language for writing. Also, provide maintainable tests for RESTful APIs. Rest Assured is utilized to test the REST APIs. Java libraries act on the Rest web services like a headless client. The Rest Assured-based libraries are also capable of validating the server's HTTP answers.

In this blog, we will be learning about the RequestSpecBuilder class. Also, we will be using it to create RequestSpecification in REST Assured. 

Class RequestSpecBuilder


The RequestSpecBuilder class in REST Assured contains several methods. These methods help to set cookies, multipart details, authentication, body, form parameters, headers, path parameters, base URI, base path, query parameters, proxy, etc. All these methods are required to build a RequestSpecification. Finally, after adding all the essential details, we use the build() method of RequestSpecBuilder class and get a RequestSpecification reference. RequestSpecification helps us to reuse the specifications. 

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Example Program

package javaPackageName;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.specification.RequestSpecification;
public class JavaClassName {
    public static void main(String[] args) {
        /* Creation of RequestSpecBuilder object */
        RequestSpecBuilder request_builder = new RequestSpecBuilder();
        /* Base URI setup */        
        /* Base Path setup */        
        /* Using builder() method for getting RequestSpecification reference */        
        RequestSpecification request_specification =;
        /* Directly calling http verbs on RequestSpecification */
        /*Response res_1= request_specification.get();
        /* In the overloaded given() method, 
        we can also pass the RequestSpecification reference variable. */
        Response res_2 = RestAssured.given(request_specification).get();
        /* Using the spec() method. 
        We can also pass RequestSpecification. */
        Response res_3 = RestAssured.given().spec(request_specification).get();


{"status":"success","data":{"id":1,"employee_name":"Tiger Nixon","employee_salary":320800,"employee_age":61,"profile_image":""},"message":"Successfully! Record has been fetched."}
{"status":"success","data":{"id":1,"employee_name":"Tiger Nixon","employee_salary":320800,"employee_age":61,"profile_image":""},"message":"Successfully! Record has been fetched."}


You can get the following exception after executing the program:

“java.lang.NullPointerException: Cannot get property ‘assertionClosure’ on null object”

In Rest Assured, there is a bug that is still open. To execute the program successfully, comment out lines 26 and 27 that read "Response res_1= reqSpec.get();".

Frequently Asked Questions

Are REST assured and REST API the same?

A Java library called REST Assured is used to test RESTful APIs. It is frequently used to test web applications that handle JSON and XML. Additionally, it supports all RESTful methods, including PUT, GET, PATCH, POST, and DELETE.

What is the difference between Postman and REST assured?

Code reusability: Since the Java client is REST-assured, it is possible. It can't be done in Postman. Creating a data-driven framework: For each collection, we can only offer one data file to the Postman automation runner. However, there is no restriction for this with REST-assured.

What is REST API in testing?

REST API, sometimes referred to as RESTful API, is an API that complies with REST's restrictions and allows communication with RESTful web services. It is an open-source automation method for testing RESTful APIs for web apps. It is frequently used to test web applications that employ JSON and XML.

Is REST assured open-source?

Yes, REST assured is an open-source Java Domain-specific language (DSL) that makes testing REST service simple.

What type of testing is done with REST assured?

Java library Rest assured is used to test Restful Web services. It can be used to test web services that are XML and JSON-based.


In this article, we have learned about the RequestSpecBuilder class in REST Assured. Also, we have seen an example where we are using the RequestSpecBuilder class. 

That's it from the article. I hope you all like it.

Also, you can check our courses and test series for your interview preparations: Coding Ninja Test SeriesCoding QuestionsInterview Preparation ResourcesCoding ContestsProduct-based Company Course, Data Science & ML courseMaster Data Analytics, and ML for beginners. You can also refer to other IT subjects like compiler design and software engineering

Happy Learning!

Previous article
REST Assured – Multiple Ways of Calling HTTP Methods on a RequestSpecification
Next article
REST Assured – Introduction to JSON and how to send files as Payload
Live masterclass