Logging request and response details is essential for debugging and ensuring that the API calls are functioning as expected. REST Assured provides built-in methods to log various parts of the request and response.
Example :
import io.restassured.RestAssured;
import io.restassured.response.Response;
public class APILoggingExample {
public static void main(String[] args) {
Response response = RestAssured.given()
.log().all() // Log all request details
.when()
.get("https://jsonplaceholder.typicode.com/posts/1")
.then()
.log().all() // Log all response details
.extract().response();
}
}?
In this example, the
log().all()
method is used to log all details of the request and response.