SoftwareTestPilot
Automation TestingPublished: 7 min read

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.

Avinash K
Founder & QA Engineer at SoftwareTestPilot
Share:XLinkedInWhatsApp
cURL to Playwright API test conversion
cURL to Playwright API test conversion

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.

Frequently asked questions

1.Does Playwright support all HTTP methods?
Yes — request.get, post, put, patch, delete, head, and fetch are all available on APIRequestContext.
2.How do I share auth between UI and API tests?
Log in via the API in a global setup, save storageState, and reuse in both test.use({ storageState }) and request.newContext({ storageState }).
3.Can Playwright send binary bodies?
Yes — pass a Buffer to the data option.
4.Where do secrets go?
Environment variables or a secret manager. The converter redacts obvious tokens by default.