Skip to content
Tezmy Tools

Curl to Fetch Converter

Turn a curl command into JavaScript fetch code

POST request to https://api.example.com/v1/orders

Runs in your browser. Nothing is uploaded.

About the Curl to Fetch Converter

API documentation almost always shows examples as curl commands, but your code probably uses fetch. This converter reads a curl command and writes the matching JavaScript. It understands the method, the URL, headers, JSON and form data, basic authentication with -u, cookies, the user agent and a body from -d, --data-raw or --json. It handles quotes and line breaks with backslashes, so you can paste straight from a docs page or from the Network tab of your browser. Choose async/await or a .then chain. Options that have no fetch equivalent are listed, so nothing disappears silently. Everything is converted in your browser.

Updated October 2026

How to use the Curl to Fetch Converter

  1. 1Paste the curl command, including line breaks if it has them.
  2. 2Choose async / await or a .then() chain.
  3. 3Read the generated JavaScript on the right.
  4. 4Check the notes under the result for any flags that were ignored.
  5. 5Copy the code into your project and replace the placeholder tokens.

What gets converted

The first word that does not start with a dash is treated as the URL. -X sets the method, and if you leave it out the tool follows curl's rule: GET without a body, POST when there is data. Each -H becomes an entry in the headers object. Data given with -d, --data-raw or --data-binary becomes the body.

When you use --json, the tool also adds the JSON content type and accept headers, just as curl does. Forms from -F become a FormData object, and a value starting with @ is marked so you can attach a file from an input.

A few details are worth knowing. Header names are copied exactly as you typed them, so the converted code matches the original request. If the same header appears twice, both lines are kept, and the last one usually wins in fetch. Cookies given with -b become a Cookie header, which browsers refuse to set, so in a browser you would rely on credentials: include instead.

Tips for a clean result

  • Remove the leading dollar sign or prompt before pasting.
  • Copy as cURL from your browser's Network tab, then trim headers you do not need, such as cookies.
  • Replace tokens such as YOUR_TOKEN with an environment variable.
  • Wrap the fetch in try/catch and check response.ok.
  • Use response.json() instead of response.text() when the API returns JSON.

Related tools

Check what a header means with the HTTP Header Lookup, and decode a status code with the HTTP Status Code Lookup. Before sending a request body, tidy it with the JSON Formatter, and sign tokens for testing with the JWT Generator. Always keep secrets out of source code.

Features

  • Method, URL, headers and body
  • JSON bodies are pretty-printed with JSON.stringify
  • Basic auth, cookies and user agent
  • Form data from -F
  • Multi-line commands with backslashes
  • async/await or .then() output
  • Notes for flags that cannot be converted

Frequently asked questions

How do I convert curl to fetch?

Paste the command into the box. The page extracts the URL, method, headers and body and writes a fetch call with the same options.

Does it support JSON bodies?

Yes. When the Content-Type is JSON and the body parses, the body is written as JSON.stringify of a readable object.

What happens to -u user:password?

It becomes an Authorization header built with btoa. Take care not to commit real credentials to your code.

Why are some flags ignored?

Options such as -k, --compressed or -o control curl itself and have no direct fetch equivalent. They are listed in the note under the result.

Can I use this code in Node.js?

Yes, in Node 18 and later fetch is built in. File uploads with -F @file need extra code to read the file.

Will cross-origin rules block my fetch in a browser?

Possibly. curl ignores CORS but browsers do not, so the server must allow your origin. From Node or a server this is not an issue.

Is my command sent anywhere?

No. The conversion runs in your browser, so tokens in the command stay on your device.

Related tools