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 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?
2.How do I share auth between UI and API tests?
3.Can Playwright send binary bodies?
4.Where do secrets go?
Practice these questions
Drill 200+ Playwright questions with senior-SDET sample answers — locators, auto-wait, fixtures, parallelism and trace viewer.
Was this article helpful?
More from REST API Testing
REST fundamentals — verbs, status codes, contracts.
- Experience-Level QA InterviewsAPI Testing Interview Questions for 1 Year Experience (2026 Complete Guide)
- Experience-Level QA InterviewsAPI Testing Interview Questions for 3 Years Experience (2026 Complete Guide)
- Experience-Level QA InterviewsAPI Testing Interview Questions for Senior Level (2026 Complete Guide)
Keep building your QA edge
Pillar guides- Selenium PillarSoftwareTestPilot's Selenium guide300 Selenium WebDriver Q&A — locators, waits, frameworks.
- Playwright Installation Guidehow to install Playwright step by stepInstall Playwright the right way — Node, browsers, VS Code, first test.
- cURL to Code ConverterSoftwareTestPilot's free cURL converterConvert any cURL command to Postman, Playwright, Rest Assured, k6, Cypress, Python, and more — free, in-browser.
- JSON / JSONPath / JMESPath Testerbuild API assertions in the browserDual-engine JSONPath + JMESPath tester with assertion builder and Postman/Playwright/Rest Assured export.
- Postman to Code Converterconvert Postman collection to PlaywrightConvert any Postman collection into a full Playwright, Rest Assured, k6, Cypress, Supertest, Python, or Karate test suite — folders, pm.test assertions, and environments preserved.
- XPath & CSS Selector GeneratorSoftwareTestPilot's selector generatorInteractive locator generator for Playwright, Selenium and Cypress — with Page Object export.
Practice these questions live
Rehearse with an AI QA interviewer that scores your answers in real time.
Continue reading

Playwright Locator Best Practices (2026) — The Only Guide You Need
11 min read
How to Migrate a Postman Collection to Playwright API Tests (2026 Guide)
12 min read
Why Every QA Engineer Must Master CI/CD Pipelines in 2026 (Or Risk Obsolescence)
12 min readJoin the QA Community
Connect with fellow testers, share job leads, and get career advice.
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