Ask Your Question
2

What is the method for extracting the desired data from an API response using rest Assured?

asked 2023-04-30 08:47:33 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-04-30 08:55:01 +0000

scrum gravatar image

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");
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-30 08:47:33 +0000

Seen: 10 times

Last updated: Apr 30 '23