cURL to JavaScript Converter

Runs entirely in your browser

Paste a curl command and get equivalent JavaScript fetch() code, generated directly in your browser.

Advertisement

Advertisement

What is cURL to JavaScript?

cURL to JavaScript parses a curl command's method, URL, headers and body, and generates equivalent JavaScript using the native fetch() API — useful when porting a curl example from API documentation into browser or Node.js code.

How to use cURL to JavaScript

  1. Paste a curl command into the Input box.
  2. Click Convert.
  3. Copy the generated fetch() code.

Features

  • Supports method, headers, body and HTTP Basic auth.
  • Generates fetch() code with a .then() promise chain.
  • Never runs the request itself.
  • 100% client-side — your command never leaves your browser.

Example

This curl command:

curl -X POST 'https://api.example.com/users' \
  -H 'Content-Type: application/json' \
  -d '{"name":"Ada"}'

becomes:

fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\"name\":\"Ada\"}"
})
  .then((response) => response.text())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

Tips for JavaScript developers

  • fetch() does not reject on a 4xx or 5xx response — only on a network failure. Check response.ok or response.status yourself if you need to handle HTTP errors.
  • Swap the .then() chain for async/await if you prefer: const response = await fetch(url, options); const data = await response.text(); inside an async function.
  • If the response body is JSON, use response.json() instead of response.text().
  • fetch() is built into every modern browser and into Node.js 18+ — no extra package needed.

Is cURL to JavaScript Converter safe?

Yes. Parsing your curl command and generating the fetch()-based code with its .then() chain both happen locally in your browser — the command you paste is never uploaded to our servers, and the generated code only runs when you choose to run it yourself.

Frequently Asked Questions

Which curl flags are supported?

-X/--request, -H/--header, -d/--data (and --data-raw/--data-binary/--data-urlencode), -u/--user, -A/--user-agent, -b/--cookie, --url, and a bare URL. Other flags are ignored rather than causing an error.

How is basic authentication (-u) converted?

It's converted into an Authorization: Basic header with the credentials base64-encoded, exactly as curl sends it on the wire.

Does this run the request?

No. It only generates the fetch() code — you run it yourself.

Related tools