curl to fetch or axios
Processed in your browser · nothing is uploaded
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
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.
It is pretty-printed inside JSON.stringify, which is what you want to edit next. Non-JSON bodies stay strings.
Yes. fetch gets an Authorization header built with btoa; axios gets an auth object and builds the header itself.
The ones that do not change the request: --compressed, -L, -s and -i. Anything else unrecognised is skipped rather than guessed at.
Here, yes; nothing is uploaded. Anywhere else, no: it contains your cookies and tokens.
That is the axios field name. axios serialises it for you, so pass an object rather than a JSON string.
axios rejects on 4xx and 5xx; fetch resolves and you must check response.ok. Translated code needs that adjusted.
No. The full URL goes in the url field, which works with or without a configured baseURL.
A Cookie header passed with -H is carried across. The -b form is dropped, because a browser manages its own cookie jar and Cookie is a forbidden header name for fetch.
fetch is built into every runtime that matters now. axios buys interceptors, automatic serialisation and rejection on error status. Neither answer is wrong.
fetch does, from Node 18 onwards. The btoa call for basic auth is the one line to check on older versions.
No. The command is parsed and rewritten in this page, which is the only reason it is safe to paste one with a live token in it.