Q5 of 40 · REST Assured

How do you send a GET request with query parameters in REST Assured?

REST AssuredJuniorrest-assuredquery-paramsget-requestfundamentals

Short answer

Short answer: Use .queryParam("key", value) in given() — REST Assured URL-encodes the values and appends them to the request URL. Chain multiple calls for multiple params, or pass a Map with .queryParams(map). This is distinct from path params (.pathParam()) which substitute {placeholders} in the URL.

Detail

REST Assured handles query parameter encoding so you never manually build a URL string like /users?page=1&size=20:

given()
    .queryParam("page", 1)
    .queryParam("size", 20)
    .queryParam("sort", "name,asc")

Or with a Map for data-driven tests:

given().queryParams(Map.of("page", 1, "size", 20))

Path params use .pathParam("id", 42) with a template in the path string:

given().pathParam("id", 42).when().get("/users/{id}")

Form params (.formParam()) go in the request body as application/x-www-form-urlencoded — they are not appended to the URL.

// EXAMPLE

@Test
void searchUsers_withFilters_returnsFilteredPage() {
    given()
        .baseUri("https://api.example.com")
        .queryParam("role",   "admin")
        .queryParam("active", true)
        .queryParam("page",   0)
        .queryParam("size",   10)
    .when()
        .get("/users")
    .then()
        .statusCode(200)
        .body("content.size()", lessThanOrEqualTo(10))
        .body("content.role",   everyItem(equalTo("admin")));
}

// WHAT INTERVIEWERS LOOK FOR

Knowing queryParam() vs pathParam() vs formParam() — they map to distinct HTTP concepts. Correct syntax and awareness of the Map overload for dynamic parameter sets.

// COMMON PITFALL

Manually concatenating query params into the URL string: ".when().get(\"/users?page=1\")" — this bypasses REST Assured's encoding and produces unmaintainable test code.