ZeroBloatTools LogoZeroBloatTools
Verified Preset100% Client-Side
Updated 2026-11-15•Instant Calculation

cURL JSON POST to Playwright APIRequestContext Converter

Pre-loaded with a REST JSON POST order creation cURL request demonstrating query param extraction (?notify=true), Bearer secret masking, and Playwright status assertions.

Interactive Pre-Configured Simulator
cURL Compiler Studio
Client-Side AST
Samples:
POST/v1/orders•3 headers
Raw cURL Input
AST Request InspectorParsed Cleanly
POSThttps://api.example.com/v1/orders
Query Params
1
Headers
3
Payload
JSON
Auto-masked 1 secret headers: Authorization → env vars
api.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { test, expect } from '@playwright/test';
test('POST /v1/orders', async ({ request }) => {
const response = await request.post("https://api.example.com/v1/orders", {
params: {
"notify": "true",
},
headers: {
"Authorization": `Bearer ${process.env.API_BEARER_TOKEN ?? ''}`,
"Content-Type": "application/json",
"X-Request-ID": "req_42",
},
data: {
"customerId": "cus_109",
"items": [
{
"sku": "PRO-PLAN",
"qty": 2
}
],
"currency": "USD"
},
});
// Verify HTTP status & response payload
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const body = await response.json();
expect(body).toBeDefined();
});
Terminal Execution:
npx playwright test api.spec.ts
Request Translation Reference

REST JSON POST Mapping: cURL CLI Flags → Playwright Options

How AST tokenization cleanly separates URL query parameters, secret headers, and structured JSON payloads.

cURL FlagParsed AST ElementPlaywright OutputSecret / Lint RuleResult
-X POST + URLhttps://.../v1/orders?notify=truerequest.post('.../v1/orders', ...)params: { notify: 'true' }Separates query parameters from base pathname automatically
-H AuthorizationBearer sk_live_...process.env.API_BEARER_TOKENSecret MaskedPrevents raw tokens from getting committed into git tests
--data-raw JSON{"customerId":"cus_109"...}data: { customerId, items }Typed Object LiteralEmits clean unescaped TypeScript object syntax + expect() checks
Playwright APIRequestContext Patterns

Header Normalization, Auth & Payload Mapping

  • Separates inline URL query strings (`?notify=true`) into Playwright’s structured `params` dictionary for cleaner diffing and dynamic test parametrization.
  • Detects `Authorization: Bearer ...` and automatically rewrites hardcoded API secrets into `${process.env.API_BEARER_TOKEN ?? ''}`.
  • Runs 100% in browser memory so sensitive staging keys and payloads never leave your machine.
Common cURL Conversion Bugs

Critical Errors to Avoid

Common Error: Leaving browser-specific sec-ch-ua and sec-fetch-* headers in automated API tests.
Best Practice: Browser headers like sec-ch-ua-mobile or sec-fetch-dest indicate browser state and change across browser versions. In headless CI test runs, leaving them in can trigger Cloudflare, Datadog, or AWS WAF anti-bot blocks due to header mismatch. Always strip browser-only headers from backend API tests.
Common Error: Hardcoding production Bearer tokens or API keys into git-committed test files.
Best Practice: Avoid committing raw credentials. Keep secret masking enabled to replace Authorization tokens with environment variables (process.env.API_BEARER_TOKEN), and supply the real secret via your .env file or GitHub Actions secrets.
Common Error: Using page.goto() instead of Playwright APIRequestContext for REST testing.
Best Practice: Testing backend APIs by navigating a full browser page adds massive CPU and memory overhead (rendering HTML, parsing CSS, running client JS). Use Playwright's built-in request fixture (APIRequestContext), which executes direct HTTP requests at Node.js network speeds without launching a browser window.
Frequently Asked Questions

Convert cURL JSON POST to Playwright APIRequestContext Questions Answered

How does Playwright request.post() serialize a JavaScript object in `data`?

When passing a plain JS/TS object to Playwright’s `data` option, Playwright automatically JSON-stringifies the body and sets `Content-Type: application/json` if not explicitly overridden.

Why move `?notify=true` out of the URL string into `params`?

Using Playwright’s `params` object automatically URL-encodes values and lets QA engineers dynamically toggle flags across data-driven test loops without brittle string concatenation.

Common cURL Flags Cheat Sheet

-X, --request:
HTTP Method (GET, POST, PUT, DELETE, PATCH, HEAD)
-H, --header:
Request Header ("Header-Name: value")
-d, --data, --data-raw:
HTTP Request Body / Payload (JSON, Form-UrlEncoded, Text)
-u, --user:
Basic Authentication ("username:password")
-b, --cookie:
HTTP Cookie header ("name=value; session=123")
-k, --insecure:
Allow insecure SSL/TLS connections during local testing
Security & Credential Hygiene

Security & Client-Side Privacy Notice

100% Client-Side Processing: This utility parses and generates code entirely in your local browser using an in-memory AST tokenizer. Your cURL commands, secret tokens, endpoints, and data payloads are never sent to any external server.
Environment Secret Hygiene: Always keep "Mask Auth Tokens" checked before pasting curl commands with production credentials. Never commit raw Bearer tokens, cookies, or private API keys to git repositories.