curl → fetch() · headers · body · JSON-aware · live

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.

cURL → fetch()
Input
161 B
4 lines
Output
263 B
9 lines
Status
ready
live
Ratio
1.63×
out/in
input · curl command
output · javascript
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();
Quick Start

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.

  1. 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 · -d
    input · curlloaded
    curl -X POST https://api.example.com/users \
      -H "Authorization: Bearer abc"
    67 B · 2 linesready
  2. 02

    Headers and body wire up

    Each -H flag collapses into a Headers-style object on RequestInit. The body becomes JSON.stringify(...) when --data looks like JSON, otherwise it falls back to a template literal so non-JSON payloads survive verbatim.

    Method defaults to GET, flips to POST automatically when a body is present (mirroring real cURL behaviour), and uses your explicit -X when set.

    fetch APIRequestInitHeadersJSON.stringify
    config · optionsfetch-ready
    { method: "POST",
      headers: { Authorization: "Bearer abc" },
      body: JSON.stringify({ name: "Alice" }) }
    wiredidiomatic
  3. 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 await use a route handler or module with type: "module"; otherwise wrap in an async function.

    async/awaitESMfetchNext.js
    run · asyncawait · ready
    const res = await fetch(url, opts);
    const data = await res.json();
    runnablemodern
  4. 04

    Copy or download

    Copy the snippet to your clipboard, or download as a .js file. 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-first
    export · fetch.jsready
    ✓ Copied to clipboard
    ✓ Saved: fetch-call.js
    ✓ 100% client-side
    ready to shipsuccess
Pro tips

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.

Use Cases

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 safe

API 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-preserving

Edge 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-aware

Front-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.

lossless

Quick 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-clean

Teach 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-grade
FAQ

Frequently asked questions

Yes — when --data starts with { it wraps the value in JSON.stringify(); otherwise it falls back to a template literal.
Basic auth (-u user:pass) lands in the headers via the underlying parser; cookies need manual handling because fetch() doesn't include them by default.
Not automatically — add it manually when you want cookies sent cross-origin.
Yes inside an async function or top-level await. Surround with try/catch in production.
No. Parsing and emission run locally in your browser.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!