Developer Convert

curl to axios

What to do

Processed in your browser · nothing is uploaded

Local · a copied cURL contains your credentials
Advertisement
320 × 100

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

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

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.

axios, request config
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding