art_tykh
art_tykh

Reputation: 169

Array in get parameter Rest Assured

I need to send the following GET request with Rest Assured:

http://some.url.com/path?filter[key1]=value1&filter[key2]=value2

I was trying to do it with queryParams and formParams, but it constructs params as filter={"key":"value"}.

In JQuery I can do this with:

$.param({filter:{key1:"value1"}})

Upvotes: 3

Views: 2113

Answers (2)

N..
N..

Reputation: 956

I did similar thing using following way

String path = "path?";
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("q", search));
            nameValuePairs.add(new BasicNameValuePair("lang", lang));
            nameValuePairs.add(new BasicNameValuePair("sort", sort));
            path = path + URLEncodedUtils.format(nameValuePairs, "utf-8");
            System.out.println("REQUEST URL " + path);
            response = given().auth().preemptive().basic(user, pass).when().get(path);

Upvotes: 0

kstandell
kstandell

Reputation: 785

According to the Rest-Assured usage guide

Parameters can also be set directly on the url:

..when().get("/name?firstName=John&lastName=Doe");

Could you not just use a formatted String with the values you want if you are not getting the desired result from the queryParam and formParam methods?

Upvotes: 2

Related Questions