curl to fetch, axios and Python
Paste a curl command, or one copied from your browser's dev tools, and get the same request as JavaScript fetch, axios or Python requests code.
API docs show examples as curl commands, and browser dev tools let you copy any request as one. Turning that into code by hand means getting every header, quote and body field right. Paste a curl command below and get the same request as fetch, axios or Python requests. The conversion runs in your browser, so tokens and cookies in the command stay on your machine.
Converted in your browser. Commands often contain tokens and cookies; nothing is sent anywhere or saved.
const response = await fetch("https://api.example.com/v1/posts?draft=false", { method: "POST", headers: { "accept": "application/json", "authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyXzU1MSJ9.c2lnbmF0dXJl", "content-type": "application/json", }, body: JSON.stringify({ title: "Hello from curl", tags: [ "cron", "jwt", ], published: true, coverImage: null, }), }); if (!response.ok) throw new Error(`HTTP ${response.status}`); const data = await response.json(); console.log(data);
| Method | POST |
| URL | https://api.example.com/v1/posts |
| Query | draft = false |
| Headers | accept: application/jsonauthorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyXzU1MSJ9.c2lnbmF0dXJlcontent-type: application/json |
| Removed | sec-ch-ua-platform, sec-fetch-mode, accept-language (added by browsers; not needed in code) |
| Body | JSON {
"title": "Hello from curl",
"tags": [
"cron",
"jwt"
],
"published": true,
"coverImage": null
} |
| Redirects | Followed (-L) |
Copying a request from your browser
Every major browser can copy a request it made as curl:
- Open dev tools (F12) and go to the Network tab.
- Do the thing in the page that makes the request, and click it in the list.
- Right-click it and choose Copy → Copy as cURL. On Windows, Chrome and Firefox offer a Windows version and a bash or POSIX version; either works here.
Browsers add a lot of headers your code doesn't need, such as sec-ch-ua, sec-fetch-mode and accept-language. Remove browser-only headers strips them out; untick it to keep everything.
A copied command usually includes your session cookie or an Authorization token. Treat it like a password: don't paste it into chat, issues or tools that send it to a server.
What the common flags become
| curl | fetch | axios | requests |
|---|---|---|---|
-X POST |
method: "POST" |
method: "post" |
requests.post(…) |
-H 'Name: value' |
headers: {…} |
headers: {…} |
headers={…} |
-d / --data-raw with JSON |
body: JSON.stringify(…) |
data: {…} |
json=… |
-d 'a=1&b=2' |
body: new URLSearchParams(…) |
data: new URLSearchParams(…) |
data={…} |
-F 'file=@photo.jpg' |
FormData |
FormData |
files={…} |
-u user:pass |
Authorization: Basic … |
auth: {…} |
auth=(…) |
-b 'session=abc' |
Cookie header |
Cookie header |
cookies={…} |
-m 10 |
AbortSignal.timeout(10000) |
timeout: 10000 |
timeout=10 |
-k |
not possible per request | httpsAgent |
verify=False |
Flags that only change what curl prints, like -s, -v, -i and -o, have no equivalent and are skipped.
Differences that catch people out
-dsends form data unless you say otherwise.curl -d '{"a":1}'labels the bodyapplication/x-www-form-urlencoded, not JSON, and many APIs reject it. Add-H 'Content-Type: application/json', or use--json, which sets bothContent-TypeandAccepttoapplication/json. The tool warns when it sees a JSON body sent as form data.- Redirects. curl only follows redirects with
-L.fetch,axiosandrequestsfollow them by default, so the code may end up at a different URL than the command did. - Browsers ignore some headers in
fetch. Code running in a web page can't setCookie,RefererorOrigin; the browser handles those itself. The same code run in Node 18 or later sends them. -kturns off certificate checks. It's fine against a local server with a self-signed certificate, but never in production code. The generated code keeps a comment where it applies.-Gmoves the-ddata into the URL's query string and sends a GET, which is easy to miss in a long command.
If a flag can't be converted, such as a proxy, a cookie file or headers read from a file, the tool lists it under Check these instead of dropping it silently.