API testing with Playwright
Playwright's request fixture is a full API client — no separate tool needed:
const res = await request.get('/api/users')— GETawait request.post('/api/orders', { data: {...} })— POST with a JSON bodyres.status(),await res.json()— status and body
Two usage scenarios:
- Pure API tests — fast contract/logic checks without the UI
- Hybrid tests — prepare data via API (fast), walk only the part under test in the UI: for "check the cart page as a user with an order", registration + order come from the API, only the cart from the UI
The middle-level expectation: API tests verify the contract, not just status — body structure, type correctness, stable error format. The simple route: TS types + runtime validation (a library like zod, or key fields by hand).
📚 Sources and documentation
- API testingofficialplaywright.dev