Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for extracting the desired data from an API response using rest Assured is to use the "extract" method. This method allows you to extract different types of data from the response, such as status code, headers, and body. To extract data from the response, you can use one of the following methods:

  1. body() - This method allows you to extract the entire response body as a string.

  2. jsonPath() - This method allows you to extract a specific value from the response body using JSON Path expression.

  3. xmlPath() - This method allows you to extract a specific value from the response body using XML Path expression.

  4. header() - This method allows you to extract a specific header value from the response.

Example code for extracting data from response:

Response response = RestAssured.get("https://api.example.com/test");

// Extracting status code
int statusCode = response.getStatusCode();

// Extracting response body
String responseBody = response.getBody().asString();

// Extracting value using JSONPath
String value = response.jsonPath().getString("data.value");

// Extracting header value
String contentType = response.getHeader("Content-Type");