As the documentation explains:
REST Assured will automatically try to determine which parameter type
(i.e. query or form parameter) based on the HTTP method. In case of
GET query parameters will automatically be used and in case of POST
form parameters will be used.
But in your case it seems you need path parameter instead query parameters.
Note as well that the generic URL for getting a country is https://restcountries.com/v2/name/{country}
where {country}
is the country name.
Then, there are as well multiple ways to transfers path parameters.
Here are few examples
Example using pathParam():
// Here the key name 'country' must match the url parameter {country}
RestAssured.given()
.pathParam("country", "Finland")
.when()
.get("https://restcountries.com/v2/name/{country}")
.then()
.body("capital", containsString("Helsinki"));
Example using variable:
String cty = "Finland";
// Here the name of the variable (`cty`) have no relation with the URL parameter {country}
RestAssured.given()
.when()
.get("https://restcountries.com/v2/name/{country}", cty)
.then()
.body("capital", containsString("Helsinki"));
Now if you need to call different services, you can also parametrize the "service" like this:
// Search by name
String val = "Finland";
String svc = "name";
RestAssured.given()
.when()
.get("https://restcountries.com/v2/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Helsinki"));
// Search by ISO code (alpha)
val = "CH"
svc = "alpha"
RestAssured.given()
.when()
.get("https://restcountries.com/v2/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Bern"));
// Search by phone intl code (callingcode)
val = "359"
svc = "callingcode"
RestAssured.given()
.when()
.get("https://restcountries.com/v2/{service}/{value}", svc, val)
.then()
.body("capital", containsString("Sofia"));
After you can also easily use the JUnit @RunWith(Parameterized.class)
to feed the parameters 'svc' and 'value' for a unit test.