Access the built-in API context via request.get(), request.post() etc. (available as page.request or via request fixture in playwright/test) to make HTTP calls that share the browser's cookie jar
Use request.newContext({ baseURL: 'https://api.example.com', extraHTTPHeaders: { 'Content-Type': 'application/json' } }) for a standalone API context with its own state when browser-session sharing is not needed
Call request.get('/users/1') and assert with await expect(response).toBeOK() and const body = await response.json() to validate status and payload
Seed or tear down backend state via API calls in test.beforeEach / test.afterEach hooks rather than through the UI to make setup fast and deterministic
Combine API and browser assertions in one test: create a resource via request, then navigate to the UI page and assert it appears — validating both layers in one pass
Known gotchas
Cookies set during browser navigation are shared with page.request but not with a separately created request.newContext() unless you explicitly pass storageState — understand which context you are operating in
APIRequestContext follows redirects by default; if you need to assert on redirect status codes, use the failOnStatusCode: false option and inspect response.status() manually
Response bodies can only be consumed once per response object; calling response.json() after response.text() (or vice versa) will throw — read the body once and store the result
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp