REST-assured is an http testing framework. It is written mainly for REST apis but can be used for Soap, html and plain http as well.
Below is a simple example how to perform a HTTP GET call with REST-assured, and how to print out the response body
import static io.restassured.RestAssured.given;
import io.restassured.response.Response;
public class RestAssuredExample {
public static void main(String[] args) {
Response resp = given().when().get("http://localhost:8080");
System.out.println(resp.getBody().asString());
}
}
The request can be configured to do other HTTP methods, like POST and PUT, as well as setting body and headers.
given()
.header("Connection", "keep-alive");
.body("{}")
.post("http://localhost:8000");
If you want to call an endpoint over TLS, you need to relaxedHTTPSValidation to let the client trust the url destination
given().relaxedHTTPSValidation().post("https://localhost:8000");
Below is a simple way you can construct a LoadScenario with REST-assured
LoadScenario scenario = new LoadScenario() {
public void loadScenario() {
load("greeting", ()->given().when().get("http://localhost:7060/api/greeting?name=Stefan"))
.handleResult(resultHandler->{
if(resultHandler.getResponse().getStatusCode() != 100) {
resultHandler.setStatus(false);
}
})
.perform();
}
};
Here are the Maven dependencies you need to use rest-assured as the client library for your load tests
io.rest-assured
rest-assured
4.3.3