Convert cURL to fetch()
Paste a cURL command and get an idiomatic JavaScript fetch() call — method, headers, query and body all wired up. Runs entirely in your browser.
const res = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer abc123"
},
body: JSON.stringify({"name":"Alice","role":"admin"}),
});
const data = await res.json();How to convert cURL to fetch()
The parser walks your cURL flags, normalises -X / -H / -d / -u into a JavaScript options object, then renders a copy-ready fetch() invocation.
- 01
Paste cURL
Drop in a cURL command from browser DevTools (Copy as cURL), Postman’s code snippet panel, a shell tutorial, or a bug report. Multi-line continuations with
\are handled automatically.The parser recognises
-X,-H,-d,--data,--data-raw,-u, and quoted URLs — the bits 90% of real-world calls use.DevToolsPostmanmulti-line-X · -H · -dinput · curlloadedcurl -X POST https://api.example.com/users \ -H "Authorization: Bearer abc"
67 B · 2 linesready - 02
Headers and body wire up
Each
-Hflag collapses into a Headers-style object onRequestInit. The body becomesJSON.stringify(...)when--datalooks like JSON, otherwise it falls back to a template literal so non-JSON payloads survive verbatim.Method defaults to
GET, flips toPOSTautomatically when a body is present (mirroring real cURL behaviour), and uses your explicit-Xwhen set.fetch APIRequestInitHeadersJSON.stringifyconfig · optionsfetch-ready{ method: "POST", headers: { Authorization: "Bearer abc" }, body: JSON.stringify({ name: "Alice" }) }wiredidiomatic - 03
Drop into modern code
The output reads like a hand-written async/await fetch — paste into a Next.js route handler, a React Query
queryFn, a service worker, or a Cloudflare Worker. The snippet is plain ESM JavaScript, no transpile required.For top-level
awaituse a route handler or module withtype: "module"; otherwise wrap in anasyncfunction.async/awaitESMfetchNext.jsrun · asyncawait · readyconst res = await fetch(url, opts); const data = await res.json();
runnablemodern - 04
Copy or download
Copy the snippet to your clipboard, or download as a
.jsfile. The parser, mapper, and renderer all run locally — your cURL (often loaded with bearer tokens) never leaves the browser.Open DevTools → Network to verify: zero outbound requests.
clipboard.jsESMprivacy-firstexport · fetch.jsready✓ Copied to clipboard ✓ Saved: fetch-call.js ✓ 100% client-side
ready to shipsuccess
Converting between formats, safely
Pick the strictest source format
Lossy formats hide bugs. Choose JSON or YAML as your source-of-truth, convert downstream as needed.
Round-trip in CI
If your converter is idempotent, your CI can verify A → B → A equals the original. Catches subtle data loss.
Numbers vs strings differ
YAML/TOML have a number type; CSV doesn’t. Quote IDs in CSV to keep leading-zero values intact.
Watch character encoding
Source format may be Latin-1 / Windows-1252; target should be UTF-8. Convert encoding before structure.
Preserve comments where you can
YAML and TOML support comments. Don’t silently drop them — they often encode intent.
Schema-aware beats blind
Use a schema to guide conversion. Field types, required-ness, and defaults survive better with structure.
When to convert cURL
DevTools replay, docs samples, edge-function debugging.
Copy as cURL
Drop a DevTools Copy-as-cURL into your front-end as fetch(). Type information survives: numbers stay numeric, booleans stay boolean, strings stay strings. The destination parser doesn't have to re-coerce, which avoids the "'true' becomes "true"" bug class.
round-trip safeAPI docs
Pair raw cURL with idiomatic JS in your README. Run output back through the inverse converter to verify idempotent round-trips in CI. A → B → A should produce byte-identical input — if it doesn't, you've found data loss.
type-preservingEdge functions
Convert backend cURL examples to runnable Workers code. Comments and metadata survive where the target format supports them (YAML, TOML, HCL). The tool doesn't silently drop intent-encoded annotations, which keeps your config self-documenting.
schema-awareFront-end auth
Translate Postman calls into a fetch() with bearer headers. Pair with a schema (JSON Schema, OpenAPI, Zod, Pydantic) to catch shape drift on either side. Catch breaking changes at conversion time rather than at runtime in production.
losslessQuick repros
Reproduce a bug report's cURL inside the affected app. Output respects target-format conventions: quoting in CSV, indent in YAML, brackets in JSON. Existing parsers don't need patches, and the result drops into legacy pipelines unchanged.
diff-cleanTeach modern fetch
Show juniors how a cURL maps to async fetch + json(). Encoding-aware: handles UTF-8 vs UTF-16 vs Latin-1 / Windows-1252 transparently. The character-set surprise that breaks "works on my machine" doesn't apply here.
spec-gradeFrequently asked questions
Something missing?
Tell us what you need. We ship the top requests every two weeks.