Class LastAPIResponse
java.lang.Object
net.serenitybdd.screenplay.playwright.questions.api.LastAPIResponse
Query information about the most recent API response.
This question is used after an APIRequest interaction
to retrieve details about the API response.
Sample usage:
// Make an API request
actor.attemptsTo(APIRequest.get("/api/users"));
// Query the response
int status = actor.asksFor(LastAPIResponse.statusCode());
String body = actor.asksFor(LastAPIResponse.body());
boolean ok = actor.asksFor(LastAPIResponse.ok());
// Parse JSON response
Map<String, Object> json = actor.asksFor(LastAPIResponse.jsonBody());
List<Map<String, Object>> list = actor.asksFor(LastAPIResponse.jsonBodyAsList());
// Get specific header
String contentType = actor.asksFor(LastAPIResponse.header("Content-Type"));
Map<String, String> allHeaders = actor.asksFor(LastAPIResponse.headers());
// Get URL and status text
String url = actor.asksFor(LastAPIResponse.url());
String statusText = actor.asksFor(LastAPIResponse.statusText());
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic net.serenitybdd.screenplay.Question<String>body()Get the response body as a string.static net.serenitybdd.screenplay.Question<byte[]>Get the response body as bytes.static net.serenitybdd.screenplay.Question<String>Get a specific header value from the response.headers()Get all headers from the response.jsonBody()Get the response body parsed as a JSON object (Map).Get the response body parsed as a JSON array (List of Maps).static net.serenitybdd.screenplay.Question<Boolean>ok()Check if the response was successful (status 200-299).static net.serenitybdd.screenplay.Question<com.microsoft.playwright.APIResponse>response()Get the raw APIResponse object for advanced operations.static net.serenitybdd.screenplay.Question<Integer>Get the HTTP status code of the response.static net.serenitybdd.screenplay.Question<String>Get the HTTP status text of the response.static net.serenitybdd.screenplay.Question<String>url()Get the final URL after any redirects.
-
Method Details
-
statusCode
Get the HTTP status code of the response. -
ok
Check if the response was successful (status 200-299). -
statusText
Get the HTTP status text of the response. -
body
Get the response body as a string. -
bodyAsBytes
public static net.serenitybdd.screenplay.Question<byte[]> bodyAsBytes()Get the response body as bytes. -
jsonBody
Get the response body parsed as a JSON object (Map). -
jsonBodyAsList
Get the response body parsed as a JSON array (List of Maps). -
header
Get a specific header value from the response.- Parameters:
headerName- The name of the header (case-insensitive)
-
headers
Get all headers from the response. -
url
Get the final URL after any redirects. -
response
public static net.serenitybdd.screenplay.Question<com.microsoft.playwright.APIResponse> response()Get the raw APIResponse object for advanced operations.
-