Convert cURL to axios
Paste a curl command to get an axios request config — params, headers, data and auth mapped for you.
AI DevRuns in your browser — nothing uploaded
How curl options map to axios
axios takes one config object, so each part of the curl command has a clear place to go.
- The query string becomes
params. axios encodes it and adds it to the URL, so you can change values without touching the URL. - The body goes in
data. A plain object is sent as JSON with the JSON Content-Type;URLSearchParamsis sent as a form. -u user:passbecomesauth: { username, password }.--max-time 10becomestimeout: 10000— axios counts in milliseconds and has no timeout unless you set one.-Fbecomes aFormDataobject indata; axios adds the multipart boundary.-kbecomes anhttpsAgentwithrejectUnauthorized: false, and-xbecomes theproxyoption. Both only work in Node.
Unlike fetch, axios throws for any status outside 200–299. Wrap the call in try/catch and read error.response.status and error.response.data, or pass validateStatus: () => true to handle every status yourself.
Example: curl to axios
This command, pasted into the converter above, gives the code below.
curl -G https://api.example.com/v1/invoices \
-u 'YOUR_KEY_ID:YOUR_SECRET' \
-d status=unpaid \
-d limit=25 \
--max-time 10import axios from "axios";
const response = await axios({
method: "get",
url: "https://api.example.com/v1/invoices",
params: {
status: "unpaid",
limit: "25",
},
auth: { username: "YOUR_KEY_ID", password: "YOUR_SECRET" },
timeout: 10000,
});
console.log(response.status);
console.log(response.data);How it works
- 1
Reads the command like a shell
Single and double quotes, $'…' strings, backslash line breaks and Windows ^ escapes are all understood — so Chrome’s “Copy as cURL (bash)” and “(cmd)” both work.
- 2
Understands curl’s options
-X, -H, -d, --data-raw, --data-urlencode, --json, -F, -u, -b, -G, -k, -L, -x, --max-time and more — with curl’s own defaults, like POST when there’s a body.
- 3
Writes idiomatic code
json= in Python, URLSearchParams and FormData in JavaScript, a multipart writer in Go, CURLFile in PHP and a text block in Java — the way each language would normally do it, using only what ships with it where possible.
- 4
Tested against real curl
Code in all seven languages was run against a test server and checked to send the same method, URL, headers and body as curl itself.
Questions, answered
Yes. axios({ method: "get", url, params }) and axios.get(url, { params }) send the same request. The converter uses the config form so every method looks the same; switch to the shortcut if you prefer it.
Yes. When data is a plain object, axios turns it into JSON and sets Content-Type: application/json. That’s why the converter drops that header from the output.
Usually it’s CORS: the API doesn’t allow requests from your site, so the browser blocks the response. curl isn’t affected by CORS. Call the API from your server instead.
fetch is built in and needs no install. axios adds a few conveniences — params, auth, timeouts and errors on bad statuses — at the cost of a dependency. Both send the same request, so pick whichever your project already uses.
Run npm install axios. The file upload code uses fs.openAsBlob, which needs Node 20 or later.
Popular uses
Read the guide
Related tools
- Prompt CompressorCut tokens from prompts and code before you send them to an LLM.AI Dev
- Regex ExplainerPaste a regex, get plain English plus test cases.AI Dev
- AI SQL Query GeneratorEnglish to SQL for Postgres, MySQL and MSSQL.AI Dev
- JSON to Pydantic / TSInstant Pydantic models, TypeScript types or dataclasses.AI Dev