cURL to Axios
This page selects Axios output for a supported bash-style curl command. The generated JavaScript imports axios and builds a request configuration with the method, URL, headers and inline body. Text form fields can become FormData. Conversion never sends a request. Inspect the notes before using the source, especially for browser-controlled headers, JSON body transforms, redirects or Node-only handling of certificate checks.
method POST, set by -d url https://api.example.com/v1/notes headers 2 Content-Type: application/json X-Request-Label: weekly report draft body 38 bytes errors none: no unsupported flags notes - Without -L curl stops at a redirect, and this code follows it, as Axios does by default.
import axios from "axios";
const response = await axios({
method: "POST",
url: "https://api.example.com/v1/notes",
headers: {
"Content-Type": "application/json",
"X-Request-Label": "weekly report draft"
},
data: "{\"title\":\"Weekly report\",\"done\":false}"
});- Method
- POST, from -d
- Headers
- 2
- Body
- 38 bytes
- Code
- Axios
The command is converted in this tab. It is never saved, sent or added to analytics, and that matters because a pasted command often carries an Authorization header, a -u password or a session cookie. The page remembers only the language you picked, and Start over above the tool forgets it.
Examples
- one header, X-Request-Label: weekly report draft
- method PUT, body qty=3; without -X the same -d would be POST
- 3 problems flagged and not converted: nothing is run or read
What each flag becomes
| curl flag | In the code |
|---|---|
| -X, --request | the method, as written |
| -H, --header | a header; 'Name;' sends it with an empty value |
| -d, --data, --data-ascii | the body and POST, with curl's form Content-Type when none is set; @file is refused |
| --data-raw | the body, with a leading @ sent as written |
| --data-binary | the body as written; @file is refused |
| --data-urlencode | a percent-encoded part; name=value encodes only the value |
| --json | the body, with JSON Content-Type and Accept headers |
| -F, --form-string | text fields of a multipart form; file parts are refused |
| -G, --get | the data moved into the URL's query |
| -I, --head | a HEAD request |
| -u, --user | Basic auth: a header in JavaScript, and auth= in requests when the name and password are ASCII |
| --oauth2-bearer | an Authorization: Bearer header |
| -A, -e, -b | User-Agent, Referer and Cookie headers; -b with a file name is refused |
| -m, --max-time | a timeout in each library's own terms |
| -L, --location | redirects followed, the libraries' default, with allow_redirects=True for a HEAD request in requests |
| -k, --insecure | verify=False in requests, an https.Agent in Axios; an error for Fetch |
| --compressed | nothing extra: the libraries ask for compressed responses by default |
| -s, -S, -v, -i, -o, -w, --fail | listed as ignored: they change only curl's own output |
| -x, --proxy and any other flag | an error that names the flag |
Common questions
- How do I convert curl headers and JSON data to Axios?
- Paste the command and the selected Axios output shows its configuration. Supported -H headers and inline body flags are converted; --json adds the corresponding headers unless supplied explicitly. The converter reports unhandled flags instead of omitting them silently.
- Can the Axios result run in a browser or Node?
- Some requests work in either environment, but the converter cannot establish that for your URL. Browser CORS and forbidden-header rules apply, and a browser drops GET/HEAD bodies. -k is represented by a Node https.Agent and cannot disable certificate checks in a browser. Relevant differences appear in the notes.
- Will it send the same bytes for a JSON body?
- The converter keeps inline body text. When Axios would otherwise trim or re-encode JSON text, the generated configuration includes a transformRequest override. Duplicate headers, library defaults and multipart boundaries can still differ; review the source and notes rather than assuming complete curl equivalence.
- Can I convert Axios back to curl?
- No. This page accepts curl text and produces Axios source. It does not parse existing Axios programs, send the generated request or install the axios package.
Converts the text of one curl command, up to 64 KB, and never runs shell interpolation, reads a local file or sends the request, so $( ), backticks, variables and @file references are errors. Flags it does not convert are named as errors too, apart from flags that change only curl's own output, such as -s, -o and --fail, which are listed as ignored. The code carries the method, URL, body and every header the command sets, with -d meaning POST unless -X names another method, escaped for the chosen language.