curl to axios
Processed in your browser · nothing is uploaded
Turns a `curl` command into an axios request config: method, url, headers, `data` for the body and `auth` for basic credentials.
How to use the curl to axios
axios differs from fetch in ways that change the translation. The body is data rather than body and is serialised for you, so a JSON object goes in as an object rather than as a string. 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.
The other real difference is errors. axios rejects on a 4xx or 5xx, fetch resolves and leaves you to check response.ok. Code translated from one to the other without adjusting the error handling will either swallow failures or throw where it used to continue; worth checking after any conversion in either direction.
Questions
That is the axios field name. axios serialises it for you, so pass an object rather than a JSON string.
-u becomes auth: { username, password } and axios builds the header, no btoa needed.
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.
Here, yes; nothing is uploaded. Anywhere else, no: it contains your cookies and tokens.