cURL to JavaScript fetch() Converter

Paste a curl command and get a JavaScript fetch() equivalent. Handles method, headers, JSON and form bodies, and HTTP Basic auth (-u). Great for copying API docs into code.

Runs 100% in your browser — nothing is uploaded.Use this in a chain
POST2 headersbodyhttps://api.example.com/users
JavaScript (fetch)
const res = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk_test_abc",
  },
  body: "{\"name\":\"Ada\",\"role\":\"admin\"}",
});
const data = await res.json();

How to use

  1. 1
    Paste your curl command

    Copy directly from API docs, terminal history, or a Postman export. Line-continuation backslashes are handled.

  2. 2
    Read the generated fetch()

    Method, headers, and body are all mapped. JSON bodies are parsed and re-serialized so you can edit the object in code.

  3. 3
    Drop it into your app

    Works in browser fetch, Node 18+ native fetch, and (with tiny tweaks) axios.

Examples

GET with a header
Input
curl -H "Authorization: Bearer abc123" https://api.example.com/me
Output
fetch('https://api.example.com/me', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer abc123',
  },
});
Simple auth-token request. Method defaults to GET.
POST with a JSON body
Input
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Alex","role":"admin"}'
Output
fetch('https://api.example.com/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Alex',
    role: 'admin',
  }),
});
Multi-line curl handled. Body is parsed to a real object literal.
HTTP Basic auth
Input
curl -u alice:secret123 https://api.example.com/private
Output
fetch('https://api.example.com/private', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic YWxpY2U6c2VjcmV0MTIz',
  },
});
-u user:pass expands to the Basic auth header with the credentials base64-encoded.
Form-urlencoded POST
Input
curl -X POST https://api.example.com/login -d "user=alice&pass=x"
Output
fetch('https://api.example.com/login', {
  method: 'POST',
  body: 'user=alice&pass=x',
});
Body is a raw string when the payload isn't JSON. Add a Content-Type header if the API expects one.

Frequently asked

Which curl flags are supported?

-X/--request, -H/--header, -d/--data/--data-raw/--data-binary/--data-urlencode, -u/--user (Basic auth), --url, and the positional URL. Flags that don't map to fetch (-k, -L, --compressed, -s, -v, -o) are silently ignored.

Does it work with multi-line curl?

Yes — line-continuation backslashes are handled, so you can paste directly from a `curl` example in docs.

What about Node vs browser fetch?

The output is standard `fetch()` compatible with modern browsers and Node 18+. `Authorization: Basic …` is generated for `-u user:pass`; other auth schemes need to be added by hand.

Can I convert curl to node-fetch or axios instead?

The output uses the fetch standard, which works in Node 18+ natively without node-fetch. For axios, the shape is similar — the URL and options map directly.

Does it preserve JSON body formatting?

JSON in -d is parsed and re-serialized so the fetch body is JSON.stringify(...) with the parsed object literal, not a raw string. Easier to edit in your code afterwards.

Related tools