Which method is used to extract data from the response body in RestAssured?

Which method is used to extract data from the response body in RestAssured?

A) extract()
B) getBody()
C) read()
D) bodyContent()

Answer:

A) extract()

Explanation:

The extract() method in RestAssured is used to extract data from the response body. It allows you to retrieve specific values or the entire response body for further validation or processing.

For example:


import static io.restassured.RestAssured.*;

String responseBody = given().
    when().
    get("/api/resource").
    then().
    statusCode(200).
    extract().
    body().
    asString();

In this example, the extract() method retrieves the response body as a string.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top