curl to fetch() Converter

Paste a curl command and get equivalent JavaScript fetch() code, with method, headers, body, and basic auth translated. Runs entirely in your browser.

JavaScript fetch()

fetch("https://api.example.com/v1/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN",
  },
  body: "{\"name\":\"Scout\",\"role\":\"admin\"}",
})
  .then((res) => res.json())
  .then(console.log);

About this tool

API documentation almost always gives examples as curl commands, but in a web or Node app you need the same request as a fetch() call. This converter parses a curl command — handling quoted arguments and backslash line continuations the way a shell would — and emits the equivalent JavaScript fetch() snippet. It maps the flags you actually use day to day: -X/--request becomes the method, each -H/--header becomes an entry in the headers object, -d/--data (and its variants) becomes the request body, and -u/--user becomes a Basic Authorization header built with btoa(). It also fills in the details curl applies implicitly, like defaulting to POST when there is a body and adding the form Content-Type curl uses when none is specified, and it flags anything it cannot translate (such as -F multipart uploads) rather than producing wrong code. It is a best-effort translator for everyday requests, not a complete curl reimplementation. Everything runs locally, so commands containing real tokens or credentials never leave your browser.

How to use it

  • Paste a curl command (line continuations with backslashes are fine).
  • Read the generated fetch() code on the right.
  • Check any warnings for flags that need manual handling.
  • Copy the snippet into your JavaScript or TypeScript project.

Frequently asked questions

Which curl flags are supported?
The common ones for API calls: -X/--request (method), -H/--header (headers), -d/--data and its -raw/-binary/-urlencode variants (body), -u/--user (Basic auth), --url and a positional URL. Connection flags like -s, -L, -k, and --compressed are accepted and ignored because they have no fetch equivalent.
How is the request body handled?
The value after -d/--data becomes the fetch body string. Multiple -d flags are joined with & like curl does. If a body is present and you did not set a method, the method defaults to POST, matching curl behavior.
What happens with basic authentication?
A -u user:pass flag is converted to an Authorization header of the form "Basic " + btoa("user:pass"), which is exactly what curl sends. The btoa() call is left in the generated code so the encoding happens at runtime.
Why does it add a Content-Type I did not specify?
When you send a body with curl but no Content-Type header, curl defaults to application/x-www-form-urlencoded. The converter adds that header and shows a warning, so the fetch request behaves the same as the curl command did.
What about file uploads or -F multipart forms?
Multipart form uploads (-F/--form) are not auto-translated because they require constructing a FormData object, which depends on real files. The converter warns you instead of emitting code that would not work.
Is my command sent anywhere?
No. Parsing and code generation run entirely in your browser with no network calls, so curl commands containing API keys, tokens, or passwords stay on your device.

Related tools