Send Query Parameter using REST-Assured

This entry is part 14 of 14 in the series REST Assured Tutorial

In this tutorial we will send API request with Query Parameter using REST-Assured.

so What is Query Parameter ?

The below API will give us all the comments available on all the posts.

But, what if I want to get the comments made on only a specific post, lets say i want to retrieve all the comments made on postId 1. We can do something like below :

This will return all the comments made on postId “1”. Query Parameter acts as a filter on data you are retrieving. It gets you the data you are looking for and not all the irrelevant data. Lets write a script in REST-Assured to hit the API with Query Parameters. Pay attention to the .queryParam(“postId”, “1”) method. This method can be used multiple times for multiple query parameters. This method accepts parameters as key-value pairs, fist is a key and second is a value for that key. Once you add this method your API will be appended with a Question Mark “?”, followed by your query parameters.


Series Navigation<< JSON Schema Validation In Rest AssuredGet Response Body in REST-Assured using JSONPath >>