API request context
Create test data, verify endpoints, and share authentication with the browser through an APIRequestContext.
- Setup Create state before opening the page
- Shared state Browser and API requests use the same cookies
- Response evidence Keep response data and network traces together
Create state before opening the page
Send GET, POST, PUT, PATCH, DELETE, or HEAD requests from PHP. JSON and form data travel with the request, and response assertions verify the endpoint contract.
Network and API testing →$response = $context->request()->post('/api/orders', [
'data' => ['sku' => 'PW-1'],
]);
Expect::response($response)->toBeOK();Browser and API requests use the same cookies
A request context obtained from BrowserContext shares its cookie jar. API setup can authenticate the browser, and browser authentication can authorize direct requests.
Handling authentication →Keep response data and network traces together
Inspect status, headers, text, and JSON directly in PHP. HAR tracing records the request flow when a backend check needs deeper evidence.
Choosing assertions →Move from the tour to working code.
Choose the explanation, recipe, or runnable example that matches what you need next.