Below is an example of how to use REST Assured to send a GET request and validate the response :
import io.restassured.RestAssured;
import io.restassured.response.Response;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class RestAssuredExample {
public static void main(String[] args) {
// Base URI
RestAssured.baseURI = "https://jsonplaceholder.typicode.com";
// Perform a GET request and validate the response
given()
.log().all() // Log request details
.when()
.get("/posts/1") // Send GET request to /posts/1
.then()
.log().all() // Log response details
.assertThat()
.statusCode(200) // Verify the status code is 200
.body("id", equalTo(1)) // Verify the JSON field 'id' is 1
.body("title", notNullValue()); // Verify the title is not null
}
}?