APIRequestContext

Playwright\API\APIRequestContextInterface

Executes HTTP requests through Playwright. Use a context to prepare application state without driving a browser page. Request options apply to a single call unless configured when it is created.

Methods

get()

APIResponseInterface

Sends a GET request. Resolves relative URLs against the configured base URL. Returns a response object even for unsuccessful HTTP status codes.

function get(string $url, array $options = []): APIResponseInterface

post()

APIResponseInterface

Sends a POST request. Request options can provide data, form fields, headers, and timeouts. Returns a response object even for unsuccessful HTTP status codes.

function post(string $url, array $options = []): APIResponseInterface

put()

APIResponseInterface

Sends a PUT request. Request options can provide data, form fields, headers, and timeouts. Returns a response object even for unsuccessful HTTP status codes.

function put(string $url, array $options = []): APIResponseInterface

patch()

APIResponseInterface

Sends a PATCH request. Request options can provide data, form fields, headers, and timeouts. Returns a response object even for unsuccessful HTTP status codes.

function patch(string $url, array $options = []): APIResponseInterface

delete()

APIResponseInterface

Sends a DELETE request. Request options can provide headers, query parameters, and timeouts. Returns a response object even for unsuccessful HTTP status codes.

function delete(string $url, array $options = []): APIResponseInterface
APIResponseInterface

Sends a HEAD request. Request options can provide headers, query parameters, and timeouts. Returns a response object without downloading a response body.

function head(string $url, array $options = []): APIResponseInterface

fetch()

APIResponseInterface

Sends an HTTP request. The method, headers, body, and retry behavior are provided in options. Relative URLs resolve against the base URL configured for this context.

function fetch(string $urlOrRequest, array $options = []): APIResponseInterface

storageState()

array

Returns the context storage state. The returned cookies and origins can initialize another API or browser context. Pass a path to save the serialized state for later reuse.

function storageState(?string $path = null): array

tracing()

TracingInterface

Tracing controls for this context. A context obtained from a browser context traces into that same browser context.

function tracing(): TracingInterface

dispose()

void

Releases the request context. Cancels pending work owned by this context on the Playwright server. Do not use the context for further requests after disposal.

function dispose(): void