Rest Assured setup
Create a Maven project and add Rest Assured in pom.xml. This gives you the core API testing library for Java.
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>5.3.0</version> </dependency>
Base URI
Set the base URI once for all requests. Using a local API makes tests faster and isolated from external services.
RestAssured.baseURI = "http://localhost:3000";
GET requests
Use given().when().get() to request resources. Verify the HTTP status code and response payload.
given()
.when()
.get("/booking")
.then()
.statusCode(200);
given()
.when()
.get("/booking/1")
.then()
.statusCode(200);
Validate response
Extract JSON values and assert the response body using Hamcrest matchers.
Response response = given()
.header("Content-Type", "application/json")
.when()
.get("/booking/1")
.then()
.statusCode(200)
.extract().response();
String firstName = response.jsonPath().getString("firstname");
response.then().body("id", equalTo(1));
Schema validation can be added later with JsonSchemaValidator.matchesJsonSchemaInClasspath, but start with basic request and response checks first.
Local REST notes
This page uses your local REST training notes for the example flow and API concepts.
Open local REST notes