How to Read a cURL Command and Turn It Into Fetch or Python Code

Understand the curl flags in API docs and DevTools (-X, -H, -d, -F, -u), how each maps to fetch, axios or Python requests, and what gets lost in translation.

Updated September 29, 2026 6 min read

Use the free cURL to Code ConverterTurn curl commands into fetch, axios, Python requests, PHP or Node code

API documentation almost always shows examples as curl commands. Browser DevTools can copy any request "as cURL". Support teams ask for "the curl that reproduces it". Curl has become the common language for describing an HTTP request, but you rarely want to ship a shell command: you need the same request in JavaScript, Python or PHP.

This guide explains what the common curl options actually do, shows how each one maps to code, and points out the options that do not translate cleanly, so the code you end up with sends exactly the request you meant.

Anatomy of a curl command

Here is a typical example from an API reference:

curl -X POST 'https://api.example.com/v1/orders?status=open' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"customer_id": 1042, "items": [{"sku": "A-100", "qty": 2}]}'

Read it in pieces:

  • curl is the program, followed by options and a URL, in any order.
  • -X POST sets the HTTP method. Without it, curl uses GET, or POST if you send data with -d.
  • The URL includes the query string. Quote it, because ? and & mean something to the shell.
  • -H 'Name: value' adds a request header. Repeat it for each header.
  • -d '...' sends a request body.
  • The backslashes at line ends are shell line continuations. They are not part of the request.

The single quotes matter too. In bash and zsh, single quotes stop the shell from touching $, ! or double quotes inside the JSON. Windows cmd.exe does not understand single quotes, which is why DevTools offers a separate "Copy as cURL (cmd)" option.

The options you will meet most

Option What it does In code
-X, --request Sets the method method: "PUT"
-H, --header Adds a header an entry in headers
-d, --data Sends a body, default type application/x-www-form-urlencoded body
--data-raw Like -d but @ is not treated as a file body
--data-urlencode URL-encodes the value before sending an encoded form field
--json Sends JSON and sets Content-Type and Accept body plus JSON headers
-F, --form Sends multipart/form-data, @ attaches a file FormData
-u user:pass HTTP Basic authentication Authorization: Basic ...
-G Moves -d data into the query string as a GET query parameters
-b, --cookie Sends a Cookie header Cookie header
-L Follows redirects default in fetch and requests
-k Skips TLS certificate checks verify=False in Python; avoid

-d versus -F

This is where many conversions go wrong. -d sends one body string, and unless you add a Content-Type header, curl labels it as a URL-encoded form (name=Jane&plan=pro). -F builds a multipart body with separate parts, which is the only way to upload a file the way an HTML form does. A server that expects one will usually reject the other with a 400 or 415.

-u and Basic auth

-u api_user:s3cret is shorthand for a header containing Basic plus the Base64 of api_user:s3cret:

Authorization: Basic YXBpX3VzZXI6czNjcmV0

Base64 is not encryption; anyone who sees the header can decode it with a Base64 converter. Only send Basic auth over HTTPS.

The same request in JavaScript

The command above becomes this fetch() call:

const res = await fetch("https://api.example.com/v1/orders?status=open", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ customer_id: 1042, items: [{ sku: "A-100", qty: 2 }] }),
});
console.log(res.status);

Two differences to remember: fetch follows redirects by default (curl needs -L), and fetch does not throw on 4xx or 5xx status codes, so check res.ok.

Convert a command automatically

Translating long commands by hand is tedious, especially ones copied from DevTools with a dozen headers. The cURL to Code Converter parses the command in your browser.

  1. Open the cURL to Code Converter and paste your command into the curl command box. Click Sample to see an example, or Clear to start over.
  2. Choose a target tab: JavaScript fetch, Axios, Python requests, PHP cURL or Node.js https.
  3. Read the generated code in the output panel, then copy it or download it as a file.
  4. Check the summary underneath: Method, URL, number of Headers, and the Body type (none, JSON, text/form-urlencoded or multipart form).
  5. Look for an Ignored options line. It lists flags the converter did not translate, and it warns when a -d @file body refers to a file whose contents it cannot read, in which case a placeholder is used.

To capture a request from a web app, open DevTools, go to the Network tab, right-click the request and choose "Copy as cURL (bash)", then paste it in.

Other ways to convert

  • Postman and Insomnia can import a curl command and generate code snippets in many languages. They are useful if you want to keep the request in a collection and run it repeatedly.
  • Writing it by hand is fine for short commands, and it forces you to understand each header. For long DevTools captures, automation saves time.
  • Running curl itself from a script is sometimes simplest for one-off admin jobs, but it adds a process dependency and makes error handling harder than a native HTTP client.

Pitfalls when converting

Headers you do not need

DevTools copies every header the browser sent: sec-ch-ua, accept-language, cookies and more. Most are irrelevant for a server-to-server call and some, such as cookies, contain session secrets. Remove what you do not need before committing the code.

Secrets in the command

A copied command contains live tokens and cookies. Replace them with environment variables in the final code, and avoid pasting real production tokens into shared chats or tickets.

Quoting and escaping

If the JSON body contains single quotes, the curl command will use shell tricks like '\'' to embed them, which is easy to break when editing. The string escape tool helps when you need to embed JSON inside another string safely, and the JSON formatter makes a minified body readable before you convert it.

Query strings with special characters

Spaces and symbols in a URL must be percent-encoded. If the converted request fails but curl worked, compare the URLs character by character. The URL encoder shows exactly what each character should become.

Reading the result

Once the code runs, the status code tells you whether the request matched what the server expected. The guide to HTTP status codes explains what 400, 401, 415 and 422 usually point to.

Frequently asked questions

What does -d do in curl?

It sends data in the request body and switches the method to POST unless -X or -G says otherwise. Without a Content-Type header, curl marks the body as a URL-encoded form.

What is the difference between -d and --data-raw?

With -d, a value starting with @ is read from a file. --data-raw sends the value exactly as written, including a leading @.

Why does my converted fetch call fail with a CORS error when curl works?

Browsers enforce CORS and curl does not. If the API does not allow your site's origin, call it from your server instead of from browser JavaScript.

Is -k safe to use?

Only for local testing. It disables certificate verification, which removes protection against someone intercepting the connection. Fix the certificate rather than copying -k into code.

How do I send a file with curl?

Use -F "file=@report.pdf" for a multipart upload like an HTML form, or --data-binary @report.pdf to send the raw bytes as the whole body.

Try it now: cURL to Code Converter

Loading tool…