Xerobit

cURL Converter: Translate cURL Commands to Code

Paste any cURL command into this curl converter to generate equivalent code in Python requests, JavaScript fetch, Node axios, Go or PHP. It parses flags like -X, -H, -d, --data-urlencode, --json, -u, -F, -G, -I, -L and -k, including combined short flags such as -sSL, so you can convert curl to python or curl to fetch without leaving the page. Everything runs locally in your browser; nothing is uploaded anywhere.

Paste your full cURL command here. Line continuations with a backslash are supported. Bodies and uploads that read a local file (@file) are not converted.

Generated Code

import requests

url = 'https://httpbin.org/get'

response = requests.get(url, allow_redirects=False)
print(response.status_code)
print(response.text)

How to use the curl converter

  1. Copy your cURL command from a terminal, API documentation or network inspector.
  2. Paste it into the input box above. The curl converter handles line breaks and backslash continuations automatically.
  3. Select your target language from the dropdown: Python, JavaScript fetch, Node axios, Go or PHP.
  4. The generated code appears instantly. Copy it into your project and adjust variables as needed.

How the curl converter parses commands

The parser splits your cURL command into tokens the way a shell does: single quotes keep text literal, double quotes allow the usual backslash escapes, $'...' strings are decoded, and a trailing backslash joins lines. It identifies the HTTP method from -X, -I (HEAD), or infers POST when a body or -F form is present. Repeated -d flags are joined with & just like curl does, and -G moves the data into the query string. Headers from -H are collected in order, and -H 'Name:' removes a header. Basic authentication via -u user:pass is translated to the idiomatic mechanism of each target language.

For example, if you want to convert curl to python, the command curl -X PUT https://api.test/item/1 -H 'Content-Type: application/json' -d '{"status":"active"}' produces an import statement for requests, assigns the URL, headers and data to variables, then calls requests.put(url, headers=headers, data=data, allow_redirects=False) followed by printing the response text.

When a body is sent without a Content-Type header, curl adds application/x-www-form-urlencoded, so the generated code adds the same header explicitly. Flags like -L (follow redirects) and -k (skip TLS verification) are mapped to their equivalents in each language where possible, and a comment explains the cases where the language needs extra setup.

Converting curl to Python requests

When you convert curl to Python, the output uses the popular requests library because it is the standard for HTTP calls in Python. The mapping is straightforward:

cURL flagPython requests equivalent
-X POSTrequests.post()
-H 'Key: Val'headers={'Key': 'Val'}
-d 'body'data='body'
--json 'body'data= with content type header
-u user:passauth=('user', 'pass')
-F name=valuefiles={'name': (None, 'value')}
-kverify=False
no -Lallow_redirects=False

This makes it easy to take a working cURL command from your terminal and drop it into a Python script or Jupyter notebook without manually rewriting every parameter.

From curl to JavaScript fetch and Node axios

Translating curl to fetch uses the native fetch API, which works in browsers and in Node.js 18 and later. The generated code builds an options object with method, headers, body and redirect properties. Since fetch does not have built-in basic auth, the tool computes the Authorization: Basic ... header from the -u value. A -F form becomes a FormData object so the multipart boundary is set for you.

For server-side JavaScript, selecting Node axios produces code that uses the axios package. The body is passed as the exact string from the command, with the same Content-Type header curl would send, and redirects are only followed when you used -L. Both outputs print the response so you can see the result immediately.

Supported cURL flags reference

This curl converter supports the flags found in most API documentation and debugging workflows. Flags that do not change the request, such as -s, -v or -o, are accepted and ignored.

  • -X, --request: Sets the HTTP method (GET, POST, PUT, DELETE, PATCH and so on). Without it the method is GET, or POST when a body is present.
  • -H, --header: Adds custom headers. Repeating a header replaces the earlier value.
  • -d, --data, --data-raw, --data-binary, --data-urlencode: Sends a request body. Several flags are joined with &, and --data-urlencode percent-encodes the value.
  • --json: Sends a JSON body and adds Content-Type: application/json and Accept: application/json when you have not set them.
  • -u, --user: Provides basic authentication credentials in user:password format.
  • -F, --form: Sends multipart form data with simple name=value fields. File uploads such as -F file=@photo.png are rejected with a message because the file cannot be read in the browser.
  • -G, --get and -I, --head: Send the data as a query string, or make a HEAD request.
  • -A, -e, -b: Set the User-Agent, Referer and Cookie headers.
  • -L, --location: Follows HTTP redirects. Without it the generated code does not follow them, like curl.
  • -k, --insecure: Disables SSL certificate verification where the target language allows it.
  • --compressed: Asks for a compressed response; most clients already do this.

Common mistakes when converting manually

Developers who translate cURL commands by hand frequently run into a few pitfalls. The most common is forgetting to set the correct HTTP method: cURL defaults to GET, but adding -d silently changes it to POST. If you miss this when writing fetch or requests code, your API call will fail with a 405 Method Not Allowed error.

Another issue is header formatting. In cURL, headers are passed as 'Key: Value' strings, but in Python they must be dictionary entries and in JavaScript they must be object properties. Missing the colon split or accidentally including extra whitespace causes authentication failures. Using a dedicated curl converter avoids these transcription errors entirely.

Finally, escaping nested quotes inside JSON payloads is notoriously tricky across shell, Python and JavaScript. The generated code escapes quotes, backslashes and line breaks for each target language.

Worked examples

ExampleInputResult
Simple GET requestcURL command: curl https://httpbin.org/get; Target language: pythonimport requests / url = 'https://httpbin.org/get' / response = requests.get(url, allow_redirects=False) / print(response.status_code) / print(response.text)
POST JSON datacURL command: curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"Alice","role":"admin"}'; Target language: fetchconst options = { / method: 'POST', / headers: { / 'Content-Type': 'application/json', / }, / body: '{"name":"Alice","role":"admin"}', / redirect: 'manual', / }; / fetch('https://api.example.com/users', options) / .then((res) => res.text()) / .then((text) => console.log(text)) / .catch((err) => console.error(err));
Basic auth with headerscURL command: curl -u admin:secret https://internal.api/data -H 'Accept: application/xml'; Target language: axiosconst axios = require('axios'); / axios({ / method: 'get', / url: 'https://internal.api/data', / headers: { / 'Accept': 'application/xml', / 'Authorization': 'Basic YWRtaW46c2VjcmV0', / }, / maxRedirects: 0, / validateStatus: () => true, / }) / .then((res) => { console.log(res.status); console.log(res.data); }) / .catch((err) => console.error(err.message));
Form data fieldscURL command: curl -F 'title=Q3 Report' -F 'description=Quarterly numbers' https://upload.example.com/api; Target language: gopackage main / import ( / "bytes" / "fmt" / "io" / "mime/multipart" / "net/http" / ) / func main() { / var buf bytes.Buffer / w := multipart.NewWriter(&buf) / w.WriteField("title", "Q3 Report") / w.WriteField("description", "Quarterly numbers") / w.Close() / req, err := http.NewRequest("POST", "https://upload.example.com/api", &buf) / if err != nil { / panic(err) / } / req.Header.Set("Content-Type", w.FormDataContentType()) / client := &http.Client{ / CheckRedirect: func(req *http.Request, via []*http.Request) error { / return http.ErrUseLastResponse / }, / } / resp, err := client.Do(req) / if err != nil { / panic(err) / } / defer resp.Body.Close() / body, err := io.ReadAll(resp.Body) / if err != nil { / panic(err) / } / fmt.Println(resp.StatusCode) / fmt.Println(string(body)) / }

FAQ

What does this curl converter do?

It takes a cURL command line string and translates it into equivalent HTTP client code for Python requests, JavaScript fetch, Node axios, Go net/http or PHP cURL. You paste the command, pick a language and copy the result.

How do I convert curl to Python requests?

Paste your cURL command into the input field and select 'Python (requests)' from the language dropdown. The tool generates a ready-to-run Python script using the requests library with all headers, data and auth parameters mapped correctly.

How do I convert curl to fetch or JavaScript?

Select 'JavaScript (fetch)' to convert curl to fetch with the native API. The output includes the method, headers object, body and redirect mode, and runs in browsers and in Node.js 18 or later.

Does it support JSON payloads and basic auth?

Yes. The parser handles -d, --data-raw, --data-binary and --json flags for request bodies. The -u flag for basic authentication is converted to the appropriate auth mechanism in each target language, such as a tuple in Python or a Base64 Authorization header in JavaScript.

Is my cURL command sent to a server?

No. The entire conversion process happens locally in your browser using JavaScript. Your API keys, tokens and request bodies never leave your machine.

What about multipart form uploads with -F?

Simple -F name=value fields are supported and become multipart form fields. File references using the @ syntax are rejected with an error message, because the tool runs in your browser and cannot read files from your disk. Paste the content inline, or add the file handling in your own code.

Why would I use this instead of Postman or Insomnia?

API clients are great for interactive testing, but when you need to embed an HTTP call into a script or application, you need raw source code. This tool gives you copy-paste-ready code in five languages without requiring an account or desktop software installation.