Convert cURL to Playwright API Test — Step-by-Step
How to turn any cURL command into a Playwright APIRequestContext test. Handles headers, auth, JSON body, form-data, and multipart uploads.

2026-07-17 · By Avinash K
Chrome DevTools' "Copy as cURL" is one of the fastest ways to capture a real request. Turning that cURL into a maintainable Playwright test takes 30 seconds when you know the pattern — or one click with the free cURL → Code Converter.
The cURL
curl 'https://api.example.com/orders' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJI...' --data-raw '{"productId":42,"qty":2}'The Playwright equivalent
import { test, expect } from '@playwright/test';
test('creates an order', async ({ request }) => {
const res = await request.post('https://api.example.com/orders', {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.API_TOKEN}`,
},
data: { productId: 42, qty: 2 },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.status).toBe('created');
});Multipart uploads
const res = await request.post('/upload', {
multipart: {
file: { name: 'a.png', mimeType: 'image/png', buffer: fs.readFileSync('a.png') },
caption: 'cover',
},
});Auth patterns
- Bearer: add to headers as shown above; store the token in
process.env. - Basic:
httpCredentials: { username, password }at context level. - Cookie: use
request.newContext({ storageState })to reuse a logged-in session.
One-click conversion
Paste any cURL — even multi-line, environment-variable-heavy DevTools output — into the cURL → Code Converter and it emits Playwright, Postman, Rest Assured, k6, Python requests, Node fetch, Go, Java HttpClient, C# HttpClient, or PowerShell.