How to pass Query String Parameters in GET url using Rest Assured?
Asked Answered
R

5

17

How to pass Query String Parameters in GET url using Rest Assured?

URL is: http://example.com/building

My Query Strings are :

globalDates:{"startMs":1473672973818,"endMs":1481448973817,"period":90}
limitTo:6
loadTvData:true
startFrom:0
userId:5834fb36981baacb6a876427
Realty answered 11/12, 2016 at 10:52 Comment(0)
H
28

You can pass them as a queryParam ..

given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get("http://example.com/building"). ...
Hershelhershell answered 14/12, 2016 at 9:55 Comment(0)
M
7

And also you can put this queryparams in Map like follows,

HashMap<String, String> params = new HashMap<String, String>() {{

put("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}");

put("limitTo","6" );

,...

}}

And post it like follows,

 resp = RestAssured.given()
                    .headers(headers)
                    .queryParameters(params)
                    .post(apiURL).andReturn();
Moriyama answered 1/8, 2019 at 8:1 Comment(1)
Thank you for this, just what I was looking for! :)Bullwhip
B
1
QueryParam can be passed as:

String endpoint = "http://example.com/building"; 

var response = given()
.queryParam("globalDates", "{\"startMs\":1473672973818,\"endMs\":1481448973817,\"period\":90}")
.queryParam("startFrom", "0").queryParam("limitTo", "6").queryParam("loadTvData", true)
.queryParam("startFrom", "0").queryParam("userId", "5834fb36981baacb6a876427")
.when().get(endpoint).then();
Bemock answered 29/11, 2021 at 6:17 Comment(0)
D
0

For our api with a type like this:

https://my.api.com/meeting?page=0&size=1

We have:

Response response = requestSpecification.queryParam("page", 0).queryParam("size", 1).get(baseEndpoint);
Drucilla answered 12/11, 2020 at 10:58 Comment(0)
R
-1

You can pass query string parameters in a GET URL using Rest Assured like this :

when()
  .parameter("globalDates","startMs","1474260058054","endMs","1482036058051","period","90")                              
  .parameters("limitTo","6")                                  
  .parameters("loadTvData","true")                                
  .parameters("startFrom","0")
  .parameters("userId","5834fb36981baacb6a876427");
Realty answered 18/12, 2016 at 18:51 Comment(1)
The parameter() and parameters() methods are currently deprecated.Daberath

© 2022 - 2024 — McMap. All rights reserved.