API Requests in Playwright

From the Playwright cheat sheet · API Testing · verified Jul 2026

API Requests

Send HTTP requests directly to test your API endpoints

typescript
import { test, expect } from '@playwright/test';

test('can create and fetch user', async ({ request }) => {
  const res = await request.post('/api/users', {
    data: { name: 'John', email: 'john@test.com' },
  });
  expect(res.ok()).toBeTruthy();

  const users = await request.get('/api/users');
  expect(await users.json()).toContainEqual(
    expect.objectContaining({ name: 'John' })
  );
});
💡 The request fixture uses baseURL from config — no need for full URLs
⚡ Combine API calls with UI testing to set up state quickly without clicking through forms
📌 The request fixture shares cookies/auth state with the browser context
🟢 Use API testing for fast backend validation without the overhead of browser rendering
apirequesthttp
Back to the full Playwright cheat sheet