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 Kamble
Founder & QA Engineer at SoftwareTestPilot
Reviewed by Priyanka G.
Share:XLinkedInWhatsApp

2026-07-17 · By Avinash Kamble, reviewed by Priyanka G.

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.
Keep going

Practice these questions

Drill 200+ Playwright questions with senior-SDET sample answers — locators, auto-wait, fixtures, parallelism and trace viewer.

Found this useful?
Share:XLinkedInWhatsApp

Was this article helpful?

Cluster · API Testing

More from REST API Testing

REST fundamentals — verbs, status codes, contracts.

Pillar guide · 30 articles
More in this cluster
From the API Testing pillar

Keep building your QA edge

Practice these questions live

Rehearse with an AI QA interviewer that scores your answers in real time.

Start a Free AI Mock Interview →

Continue reading

Join the QA Community

Connect with fellow testers, share job leads, and get career advice.

Premium QA Resources

Stop Reinventing the Wheel. Upgrade Your QA Arsenal.

Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.

  • Ready-to-use testing strategy templates
  • Advanced API & UI automation guides
  • ⏱️ Save 10+ hours a week on test planning
4.9/5 rating
Explore All Products

⭐⭐⭐⭐⭐ Trusted by 1,000+ Software Test Pilots • Instant Access