Developer Convert

curl to fetch or axios

What to do

Processed in your browser · nothing is uploaded

Local · a copied cURL contains your credentials

Turns a curl command into a fetch call or an axios request config: method, headers, body and basic auth, including the backslash-continued multi-line form a browser’s "Copy as cURL" produces. Four flags that only change how curl itself behaves (--compressed, -L, -s and -i) are dropped rather than translated.

How to use the curl to fetch or axios

1 Paste your input. The result appears immediately.
2 Pick the operation you want.
3 Copy the result, or save it as a file.

The workflow this exists for is the one every developer has: open the network tab, right-click a request, copy as cURL, and now you need it in code. The command that gives you is long, backslash-continued and full of headers, and translating it by hand is tedious rather than hard.

A JSON body is pretty-printed into a JSON.stringify call rather than left as a string, because that is what you want to edit next. A body that is not JSON, form encoded or plain text, stays a string, since reformatting it would change it.

axios differs from fetch in ways that change the translation, which is why both are here rather than on separate pages. The body is data rather than body and axios serialises it for you, so an object goes in as an object; passing JSON.stringify(…) to axios and also setting a JSON content type is a common way to end up with a double-encoded body. Basic auth is a first-class field: -u user:pass becomes auth: { username, password } and axios builds the header, which is tidier than the btoa dance fetch needs and works in Node, where btoa historically did not exist. And the errors differ. axios rejects on a 4xx or 5xx while fetch resolves and leaves you to check response.ok, so code moved from one to the other without adjusting its error handling will either swallow failures or throw where it used to continue.

One warning that matters. A copied cURL contains your live cookies and Authorization header, which are credentials. Do not paste that command into a chat, a ticket or a public snippet without removing them first. Nothing typed here is uploaded, but the same command is dangerous everywhere else, and people paste it into things that are not local far too readily.

What people use it for

  • Turning a copied network request into JavaScript
  • Rewriting the same command as an axios config
  • Reproducing an API call from documentation in code
  • Checking which headers a curl command actually sets

Questions

Yes, including the backslash-continued multi-line form and the long header list.

MDN. Using the Fetch APIcurl manual
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding