Skip to content

curl to JavaScript Converter

Paste a curl command and get JavaScript using the built-in fetch API, which works in every modern browser and in Node.js 18+ with no dependencies.
const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer YOUR_TOKEN",
  },
  body: JSON.stringify({
    "title": "Hello",
    "body": "From curl",
    "userId": 1
  }),
});

const data = await response.json();
console.log(data);

Converted in your browser. Commands often contain API keys, so nothing is sent anywhere or saved.

How to convert curl to JavaScript

  1. Paste your curl command (from API docs, a terminal or your browser's dev tools).
  2. The JavaScript code appears instantly, using fetch. Switch tabs to see other languages.
  3. Copy the code and run it; no extra packages are needed.

How curl options map to fetch

curlJavaScript
-X POSTmethod: "POST"
-H 'Name: value'headers: {...}
-d '{"json": true}'body: JSON.stringify({...})
-F 'name=value'body: FormData
-u user:passAuthorization: "Basic " + btoa("user:pass")
-m 10signal: AbortSignal.timeout(10000)
-kNot possible in fetch (fix the certificate)

Tips for the generated JavaScript code

  • fetch doesn't throw on 4xx or 5xx responses. Check response.ok (or response.status) before using the body.
  • In the browser, the API must allow your site with CORS headers. If curl works but fetch fails with a CORS error, call the API from your server instead.
  • Never put secret API keys in browser code; anyone can read them. Call keyed APIs from a server or serverless function.

Convert curl to other languages

The same converter writes Python, Node.js (axios), Go, PHP and Ruby. See the cURL converter for every supported option.

Need an API to try it on? Every API in our list of APIs with no key works with a plain curl command.

Frequently asked questions

Why does my request work in curl but fail in the browser?

Almost always CORS. curl doesn't enforce it, but browsers block responses from APIs that don't send Access-Control-Allow-Origin for your site. The fix is on the API's side, or proxy the call through your own server.

How do I send basic auth with fetch?

Add an Authorization header with "Basic " followed by base64 of user:password, e.g. headers: { Authorization: "Basic " + btoa("user:pass") }. The converter does this for curl -u.

Does fetch follow redirects like curl -L?

Yes, fetch follows redirects by default. Use redirect: "manual" to stop at the first response, like curl without -L.

How do I copy a request as cURL from Chrome?

Open DevTools (F12), go to the Network tab and reload. Right-click the request, choose Copy, then Copy as cURL (bash). Paste it here. Chrome's Windows (cmd) format works too.

Is it safe to paste commands that contain API keys?

Yes. The conversion runs entirely in your browser; nothing you paste is sent to a server, logged or saved. Still, rotate any key you've shared publicly.

More free developer tools