🔁
Developer Tools
May 21, 20267 min readBy BrowseryTools Team

How to Convert cURL to Code (fetch, Python requests, Node.js)

Paste a cURL command and get working JavaScript fetch, Python requests, or Node.js code — including the DevTools 'Copy as cURL' trick. Learn how each flag maps to code so you can trust the output, all processed locally in your browser.

curl to codecurl to fetchcurl to pythonconvert curlcopy as curlapi

You found the API call you need — but it is written in cURL, and you are working in JavaScript or Python. Or you opened your browser’s DevTools, right-clicked a request, and chose “Copy as cURL,” and now you have a wall of flags you need to turn into real code. Translating cURL by hand is fiddly: every -H, -d, -u, and -X has to map to the right argument in your language, and a single missed header breaks the request.

The BrowseryTools cURL Converter does it instantly — paste a cURL command and get clean code in JavaScript fetch, Python requests, Node.js, and more, all in your browser with nothing uploaded. This guide shows the flag-to-code mapping so you can read and trust the output.

The “Copy as cURL” Workflow

The fastest way to get a working request is to let the browser write it for you. Open DevTools (F12), go to the Network tab, perform the action you want to replicate, then right-click the request and choose Copy → Copy as cURL. You now have a cURL command with the exact headers, cookies, and body the real site sent. Paste it into the converter and you get the same request as code you can drop into your project.

How cURL Flags Map to Code

Once you know the handful of flags that matter, you can read any cURL command at a glance:

-X POST          ->  the HTTP method
-H "Key: Value"  ->  a request header
-d '{...}'       ->  the request body (implies POST)
-u user:pass     ->  HTTP Basic auth
-F field=value   ->  multipart/form-data upload
-b "name=value"  ->  a cookie
-L               ->  follow redirects

A header like -H "Authorization: Bearer abc123" becomes an entry in the headers object. A body passed with -d becomes the request body, and if the content type is JSON it gets serialized accordingly. -u user:pass becomes a Basic auth header. Knowing this mapping is what lets you sanity-check generated code instead of blindly trusting it.

The Same Request in Three Languages

Take a simple authenticated POST. In cURL:

curl -X POST https://api.example.com/users \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada"}'

As JavaScript fetch:

fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Authorization": "Bearer TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ name: "Ada" }),
});

As Python requests:

import requests

requests.post(
    "https://api.example.com/users",
    headers={"Authorization": "Bearer TOKEN"},
    json={"name": "Ada"},
)

Notice how Python’s json= argument sets the body and the Content-Type header automatically — a small idiomatic difference the converter handles for you.

Common Gotchas

Quoting and escaping. cURL bodies are wrapped in single quotes in the shell; when those contain JSON with double quotes, manual translation is where bugs creep in. Letting a converter parse it removes that risk.

Implicit POST. Using -d makes a request POST even without -X POST. If you only translate the visible flags you might wrongly produce a GET.

Secrets in the command. A copied cURL request often contains live tokens and cookies. Because the converter runs entirely in your browser, those secrets are never sent to a server — but you should still scrub them before pasting code into a shared repo or ticket.

Frequently Asked Questions

Which languages can I convert to? JavaScript fetch, Python requests, Node.js, and other common targets.

Does the converter send my command anywhere? No. Parsing and conversion happen locally in your browser, so any tokens in the command stay on your device.

Can I paste a “Copy as cURL” from DevTools? Yes — that is one of the best uses. It captures the exact headers and body of a real request.

Is it free? Yes — no account, no limits.

Convert Now

Open the cURL Converter, paste your command, and copy the equivalent code. For a deeper look at cURL syntax and REST patterns, read our guide to converting API requests between languages, and to make sense of the responses you get back see the HTTP status codes guide.


🛠️

Try the Tools — 100% Free, No Sign-Up

Everything runs in your browser. No uploads. No accounts. No ads.

Explore All Tools →