APIResponse

Playwright\API\APIResponseInterface

Represents an HTTP API response. Status, headers, and body data originate from an API request. Response accessors do not perform additional network requests.

Methods

ok()

bool

Reports whether the response succeeded. Status codes from 200 through 299 are considered successful. Redirect and client or server errors return false.

function ok(): bool

status()

int

Returns the HTTP status code. The value is the code received from the remote server. Use ok() when only the success range matters.

function status(): int

statusText()

string

Returns the HTTP status text. The value comes from the remote server response when available. An empty string represents a missing status text.

function statusText(): string

url()

string

Returns the final response URL. Redirects can make this differ from the request URL. An empty string represents a missing URL in the protocol response.

function url(): string

headers()

array

Returns one value per response header. Repeated headers retain their first value in this representation. Header names preserve the casing supplied by the server.

function headers(): array

headersArray()

array

Returns all values for every response header. Repeated headers remain separate values in the returned arrays. Header names preserve the casing supplied by the server.

function headersArray(): array

headerValue()

?string

Returns the first value for a response header. Header name matching is case-insensitive. Returns null when the response does not contain the requested header.

function headerValue(string $name): ?string

headerValues()

array

Returns all values for a response header. Header name matching is case-insensitive. The returned array is empty when the response does not contain the header.

function headerValues(string $name): array

body()

string

Returns the response body as text. This is an alias for text() provided for API parity. No content decoding is applied beyond the Playwright protocol response.

function body(): string

json()

array

Decodes the response body as JSON. The top-level JSON value must be an object or array. Invalid JSON raises a Playwright exception.

function json(): array

text()

string

Returns the response body as text. The returned string is the body received through the Playwright protocol. An empty string represents a missing body.

function text(): string

dispose()

void

Releases response resources. Call this when a response implementation holds disposable resources. The bundled implementation currently retains only in-memory response data.

function dispose(): void