Convert curl commands to JavaScript fetch code instantly. Free online curl to JS converter that handles headers, authentication, and request bodies.
Copy a curl command from your terminal, API documentation, or browser DevTools.
The converter runs entirely in your browser. No data is sent to any server, so you can safely paste commands containing API keys, tokens, or internal endpoints.
The Fetch API uses an options object as the second argument. Here is how curl flags translate:
| Curl flag | Fetch API equivalent |
|---|---|
| -X POST | method: 'POST' |
| -H 'Key: Value' | headers: { 'Key': 'Value' } |
| -d '{"key":"val"}' | body: '{"key":"val"}' |
| -L (follow redirects) | redirect: 'follow' (default) |
| -b 'cookie=val' | Added to headers as Cookie |
The generated code uses the Fetch API, which is available natively in all modern browsers and in Node.js 18+. If you are running Node.js 16 or earlier, you will need a polyfill like node-fetch.
In a browser context, the generated code works inside any async function or at the top level of an ES module. The await keyword pauses execution until the response arrives, then response.text() or response.json() gives you the body.
This converter generates Fetch API code because it is the standard built into browsers and Node.js, so no dependencies are required. If your project uses axios, the generated code is still useful as a starting point: the headers object and body string are identical.
To adapt the output for axios, replace fetch(url, options) with axios({ url, ...options }) and change body to data. The rest carries over directly.
Bearer tokens in curl (-H 'Authorization: Bearer token123') pass through as a regular header in the fetch options. The converter preserves the exact header value from the curl command.
For basic auth (-u user:pass), the converter adds a comment showing how to create the Authorization header using btoa(). The Fetch API does not have a built-in auth parameter like Python's requests library, so the base64 encoding step is necessary.
Cookies from -b are added to the headers object. In a browser, you may also want to set credentials: 'include' to send cookies from the browser's cookie jar.
The generated code calls response.text() to read the response body as a string. If you know the API returns JSON, replace response.text() with response.json() to get a parsed JavaScript object directly.
For error handling, check response.ok before reading the body. The Fetch API does not throw on HTTP errors (4xx, 5xx). It only throws on network failures. Adding an if (!response.ok) check is recommended for production code.
Paste your curl command into the input field above, select "JavaScript," and click Convert. The output uses the Fetch API with async/await syntax and is ready to use in browsers and Node.js 18+.
Yes. This tool generates Fetch API code directly. The output includes the method, headers, and body options mapped from the curl flags.
Yes. The Fetch API is available natively in Node.js 18 and later. For earlier versions, install the node-fetch package and add import fetch from 'node-fetch' at the top.
The headers and body from the generated fetch code work with any JavaScript HTTP client. Replace fetch() with axios() and change body to data.
No. All conversion happens in your browser. Nothing leaves your machine.
Bearer tokens are passed as a header (Authorization: Bearer ...). For basic auth, the converter shows how to use btoa() to encode the credentials. Both are included in the generated output when present in the curl command.
Structured page data instead of raw HTML. Your agent processes less, decides faster, and costs less to run.