cURL to Code Converter

Convert a curl command into Python requests, JavaScript fetch, Axios, Go or PHP code with headers, JSON bodies, forms and auth handled the way curl does.

The interactive tool loads here when JavaScript runs.

About this tool

What is the cURL to Code Converter?

API documentation and browser developer tools both speak curl. Paste a curl command here and get the same HTTP request as JavaScript fetch, Node.js Axios, Python requests, Go net/http or PHP's cURL extension, with the method, URL, headers, body, form fields, Basic auth, timeout and TLS options translated. The panel beside the code shows what was understood: the method, every header including the ones curl adds by itself, and the kind of body.

The parser follows curl's own rules rather than guessing. -d makes the request a POST with Content-Type application/x-www-form-urlencoded, several -d values are joined with &, --json sets both Content-Type and Accept to application/json, -G moves the data into the query string, -F builds a multipart form, and -u becomes an Authorization: Basic header. It reads bash and zsh quoting,

#x27;...' strings and backslash line continuations as well as the ^-escaped Windows cmd format from Chrome's Copy as cURL (cmd).

Nothing is executed or sent. The command, including any tokens in it, stays in your browser tab.

  • fetch, Axios, Python requests, Go net/http and PHP cURL output
  • curl semantics for -d, --data-raw, --data-binary, --data-urlencode, --json, -G and -F
  • Basic auth, cookies, user agent, referer, timeout, -k and -L
  • bash, zsh,
    #x27;...' and Windows cmd quoting
  • JSON bodies emitted as native objects or dicts
  • Summary of parsed headers and clear notes on untranslated options
  • Runs locally; the request is never sent
Read the guide: From curl to Code: What Each curl Option Means in Your Language

How to use the cURL to Code Converter

  1. Copy a request as cURL from your browser's Network panel (right-click a request, Copy, Copy as cURL) or from API documentation.
  2. Paste it into the command box. Multi-line commands with backslashes, and Windows cmd commands with ^, both work.
  3. Pick the target: fetch, Axios, Python requests, Go or PHP. The code updates immediately.
  4. Check the summary of method, URL and headers, and read the notes for anything that could not be translated, such as file paths or proxy settings.
  5. Copy or download the code and move secrets such as bearer tokens into environment variables before committing it.

Worked examples

GitHub API with Basic auth to Python

Input

curl https://api.github.com/user -H 'Accept: application/vnd.github+json' -u octocat:TOKEN

Output

response = requests.get("https://api.github.com/user", headers=headers, auth=("octocat", "TOKEN"), allow_redirects=False)

-u becomes requests' auth tuple, which sends the same Authorization: Basic header. allow_redirects=False mirrors curl without -L.

Form data to fetch

Input

curl -d 'name=Ada Lovelace' https://httpbin.org/post

Output

method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: "name=Ada Lovelace"

curl sends -d data unencoded with a form Content-Type, and so does the generated code. Use --data-urlencode in the command if the value needs encoding.

Query string built with -G

Input

curl -G https://api.example.com/search --data-urlencode 'q=rust toml' -d limit=5

Output

http.NewRequest("GET", "https://api.example.com/search?q=rust%20toml&limit=5", nil)

-G turns the data into URL parameters on a GET request, and --data-urlencode encodes the space as %20.

File upload to PHP

Input

curl -F 'file=@report.pdf' https://x.test/upload

Output

curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => new CURLFile('report.pdf')]);

Passing an array with a CURLFile makes PHP send multipart/form-data with the boundary set for you.

Background and insight

curl was first released by Daniel Stenberg in 1998 and ships with Windows, macOS and nearly every Linux distribution, which is why it became the lingua franca for HTTP examples. Its option set is large, but a handful of options cover almost every pasted command: -X for the method, -H for headers, -d and its variants for the body, -F for forms, -u for credentials, -b for cookies, -k to skip certificate checks and -L to follow redirects.

Several defaults trip people up when moving to a library. curl -d sends the data exactly as typed with a form Content-Type, while requests' data= sends a string without any Content-Type and fetch labels a string body text/plain; the generated code therefore sets the header explicitly. --data-urlencode percent-encodes the value part the way libcurl does, with spaces as %20. And curl does not follow redirects unless you pass -L, whereas fetch, requests, Axios and Go's http.Client all do; the Python, Axios and Go output turn redirects off to match curl, and the fetch output notes the difference.

For JSON bodies the converter parses the payload and emits idiomatic code: JSON.stringify() around an object literal for fetch, a plain object for Axios, a Python dict with True, False and None passed as json=, and a raw string for Go. Multipart uploads use FormData, requests' files= tuples, Go's mime/multipart writer and PHP's CURLFile, with placeholders where your file goes.

Common use cases

  • Reproducing browser requests

    Turn a request from the Network panel into a script for scraping your own data, testing or automation.

  • Using API documentation

    Most API docs show curl first. Convert the example into the language your service is written in.

  • Writing integration tests

    Start a test from the exact request that reproduces a bug, then add assertions.

  • Sharing requests with teammates

    Give a Go or PHP developer the same request you tested in a terminal.

Tips and limitations

  • Copy as cURL includes every browser header, cookies and all. Delete the ones your script does not need, especially session cookies.
  • The generated fetch code works in browsers only if the API allows your origin through CORS; the same code in Node.js 18+ has no such limit.
  • -k (insecure) is translated to the equivalent setting in each library, but only use it against test servers you control.
  • Options such as --proxy, --cert and -b with a cookie file are listed as notes because they depend on your environment.
  • If curl prompts for a password (-u user with no colon), the code uses an empty password; add the real one from a secret store.
  • The output targets Python requests 2.x, Go 1.16+ (io.ReadAll), Node.js 18+ or modern browsers for fetch, and PHP 7.4 or later.

Frequently asked questions

How do I copy a request as cURL in Chrome or Firefox?

Open developer tools, go to the Network tab, right-click the request and choose Copy, then Copy as cURL. On Windows, Chrome offers bash and cmd variants; both can be pasted here.

What is the Python requests equivalent of curl -d?

data= with the same string and an explicit Content-Type: application/x-www-form-urlencoded header, because requests does not add that header for string data the way curl does. For JSON, curl -d with a JSON Content-Type maps to json= with a dict.

Why does the generated Python code set allow_redirects=False?

curl only follows redirects when you pass -L. requests follows them by default, so the converter turns that off to make the script behave like the command. Add -L to the curl command, or remove the argument, to follow redirects.

What does curl -G do?

It sends the data given with -d or --data-urlencode as URL query parameters on a GET request instead of as a POST body. The converter appends those parameters to the URL.

Is my API key safe if I paste a command here?

The command is parsed by JavaScript in the page and is not sent anywhere. Still, treat generated code like any file with secrets and move keys into environment variables.

Does it support the --json option?

Yes. --json, added in curl 7.82.0, is shorthand for --data-binary plus Content-Type and Accept headers set to application/json, and it implies POST. Several --json values are concatenated, as curl does.

Can it convert curl file uploads?

Yes. -F name=@file becomes a multipart upload in each language, with a placeholder or file path for the content. -d @file and --data-binary @file become a body read from that file.

Is there an in-depth guide to the cURL to Code Converter?

Yes. “From curl to Code: What Each curl Option Means in Your Language” covers the background, how it works, common pitfalls and worked examples. Read the full guide.

People also search for

  • convert curl to python requests
  • curl to javascript fetch converter
  • copy as curl to axios
  • curl -d to python requests data
  • curl command to go http request
  • curl to php curl_setopt code
  • curl get request with query string data
  • curl --json flag equivalent in python