cURL to Code Converter

Convert a cURL command to JavaScript fetch() and Python requests code, carrying over its method, headers, body, form fields and basic auth.

Runs in your browser. Files never leave your device.

About the cURL to Code Converter

Paste a cURL command and this cURL to code converter writes the same request as JavaScript fetch() and as Python requests, ready to drop into a script or a web app. It's handy when you've copied a curl example from API documentation or used Copy as cURL in the browser's DevTools and want the request in the language you actually use.

The converter reads the URL, the method, headers, the request body (-d, --data-raw, --json, --data-urlencode or -F form fields), basic auth and cookies, and builds both snippets from them. Anything it can't carry across, such as a body read from a file or a proxy, is listed under Notes so nothing is dropped silently.

What the converter reads from your curl command

First the command is split into words the way a bash shell would: single and double quotes, $'…' strings, backslash escapes and lines ending in \ are all handled, so a multi-line command copied from DevTools works as it is. Commands copied in Windows cmd format (with ^ escapes) are read too. Anything after a pipe or a semicolon, such as | jq, is ignored.

Then each curl option is applied as curl itself would. -X or --request sets the method; without it, -I means HEAD, a body means POST and everything else is GET. -H adds a header, -u becomes basic auth, -b with name=value becomes a Cookie header, and -A and -e become User-Agent and Referer. Several -d values are joined with &, and -G moves them into the query string instead.

curl sends -d data as application/x-www-form-urlencoded unless you give a Content-Type, so the snippets add that header too. With a JSON Content-Type (or --json) and a body that is valid JSON, the JavaScript uses JSON.stringify({…}) and the Python uses json=, with the object laid out on separate lines. Form fields from -F become a FormData object in JavaScript and files= in Python.

Everything happens in your browser as you type. The request itself is never sent, so pasting a command that contains an API key doesn't call the API or share the key.

Assumptions and limits

  • A body read from a file (-d @data.json or -T file) can't be read here; the snippets leave the body out and a note tells you to add the file's contents. For -F photo=@me.jpg, the Python opens the file by name and the JavaScript expects a File or Blob in a variable called file.
  • Options that only change how curl shows or saves the response, such as -s, -o, -L and --compressed, are skipped because fetch and requests don't need them. Others with no equivalent, such as -x (proxy) and certificate options, are listed under Notes.
  • A JSON body with a number of 16 or more digits, or one too large to store such as 1e400, is kept as a text string, so long IDs aren't rounded or lost by JSON.parse.
  • -k (skip certificate checks) becomes verify=False in Python. fetch() has no such option, and browsers don't let fetch() set a Cookie header, so the JavaScript for those commands is meant for Node.js 18+ or Deno.
  • Both snippets expect a JSON response. For an API that returns HTML or plain text, change res.json() to res.text() and response.json() to response.text.

Worked examples

Convert curl to JavaScript fetch and Python requests

A simple GET command from an API's quick-start guide:

Input:
curl -X GET https://api.example.com/users

Output:
// JavaScript (fetch)
fetch("https://api.example.com/users", {
  method: "GET"
})
  .then((res) => res.json())
  .then((data) => console.log(data));

# Python (requests)
import requests

response = requests.get("https://api.example.com/users")
print(response.json())

A POST with a token and a JSON body

For curl https://api.example.com/v1/orders -H 'Authorization: Bearer abc' -H 'Content-Type: application/json' -d '{"qty":2}', the -d makes it a POST, both headers are copied, and the JSON body becomes an object:

fetch("https://api.example.com/v1/orders", {
  method: "POST",
  headers: {
    "Authorization": "Bearer abc",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "qty": 2
  })
})

headers = {
    "Authorization": "Bearer abc",
    "Content-Type": "application/json",
}

json_data = {
    "qty": 2,
}

response = requests.post(
    "https://api.example.com/v1/orders",
    headers=headers,
    json=json_data,
)

JSON sent without a Content-Type

curl -d '{"qty":2}' https://api.example.com/v1/orders has no Content-Type header, so curl really sends it as form data. The snippets do the same and a note points it out; add -H 'Content-Type: application/json' or use --json if the API expects JSON.

curl options and their fetch and requests equivalents

Every row is converted for you, except -L, which needs nothing.

curl optionJavaScript fetch()Python requests
-X POSTmethod: "POST"requests.post(url)
-H 'Name: value'headers: { "Name": "value" }headers={"Name": "value"}
-d '{"a":1}' with a JSON Content-Typebody: JSON.stringify({ "a": 1 })json={"a": 1}
-d 'a=1&b=2' (form)body: "a=1&b=2" plus the form Content-Typedata="a=1&b=2" plus the form Content-Type
-u user:pass"Authorization": "Basic " + btoa("user:pass")auth=("user", "pass")
-F file=@photo.jpgbody: form (a FormData with the file)files={"file": ("photo.jpg", open("photo.jpg", "rb"))}
-G -d q=tea?q=tea added to the URL?q=tea added to the URL
-L (follow redirects)Followed by defaultFollowed by default

How to use the cURL to Code Converter

  1. Paste the curl command. Put the whole command in the Input box, line breaks and all; a GET example is filled in to start with.
  2. Read the code. The fetch and requests snippets update as you type; Process runs the conversion again.
  3. Check the notes and copy. Read any Notes at the end for parts that need a hand edit, then press Copy and paste the code into your project.

Frequently asked questions

How do I convert a curl command to Python requests?

Paste the command and copy the Python half of the output. It imports requests, puts the headers in a headers dictionary and the body in json= or data=, and calls requests.get, requests.post or the matching method. Unusual methods such as PURGE use requests.request("PURGE", url).

How do I copy a request from Chrome DevTools as curl?

Open DevTools, go to the Network tab, right-click the request and choose Copy, then Copy as cURL. Paste it here as it is: the multi-line format, $'…' quoting and the Windows cmd version are all understood. DevTools copies every header, so delete the ones your code doesn't need.

Why does my converted fetch request fail with a CORS error?

Because browsers block calls to another domain unless that server allows it, and curl has no such rule. Custom headers such as Authorization can also trigger a preflight check. Run the request from your own server or Node.js, or ask the API owner to allow your site.

Does the converter handle -d, -H and authentication options?

Yes. Headers from -H, bodies from -d, --data-raw, --data-binary, --json and --data-urlencode, form fields from -F, basic auth from -u, bearer tokens from --oauth2-bearer and cookies from -b are all converted. Digest and NTLM auth and AWS request signing aren't, and appear under Notes.

Is it safe to paste a curl command that contains my API key?

Yes. The conversion runs in your browser and the request is never sent, so the key isn't used or uploaded. Do remove real keys before sharing the generated code, and keep them in environment variables in your project.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.