🔁 cURL to JavaScript Fetch Converter

Convert any cURL command to JavaScript fetch() code. Handles headers, POST, JSON, and auth. Get browser-ready fetch code instantly. Free, no signup.

Paste your curl command and select the JavaScript tab. The tool generates clean fetch() code with all headers, method, and body correctly set. The output is ready to run in a browser or Node.js — no modifications needed.

How to Use

1

Paste your cURL command

Paste your full curl command (starting with "curl") into the input area. Multi-line commands with \ are supported.

2

Choose a language

Click a language tab: Python, JavaScript, PHP, or Go. The code updates instantly.

3

Copy the code

Click Copy to copy the generated code. It handles headers, auth, and JSON bodies.

Frequently Asked Questions

What is a cURL command? +
cURL is a command-line tool for making HTTP requests. Developers use it to test APIs, download files, and debug network requests. Format: curl [options] URL. Common flags: -X (method), -H (header), -d (data), -u (auth).
What languages are supported? +
This tool generates code for Python (requests library), JavaScript (fetch API), PHP (curl extension), and Go (net/http package). Each output is idiomatic and production-ready.
How do I convert a curl with headers? +
Include -H flags in your curl command, e.g.: curl -H "Authorization: Bearer token" -H "Content-Type: application/json" https://api.example.com. All headers are extracted and included in the generated code.
Does it support POST with JSON body? +
Yes. Include -d '{"key":"value"}' or --data-raw with your JSON. The tool detects JSON content and formats it properly for each language.
What about Basic Auth? +
curl -u username:password is supported and converted to the appropriate auth mechanism in each language: HTTPBasicAuth in Python, btoa() in JS, CURLOPT_USERPWD in PHP, and SetBasicAuth in Go.


Complete Guide: cURL to Code Converter

The cURL to Code tool transforms raw curl terminal commands into clean, ready-to-run code snippets for JavaScript fetch, Axios, Python Requests, PHP cURL, and more. Whether you copied a command from browser DevTools or an API's documentation, this converter eliminates the tedious manual translation work.

Anatomy of a cURL Command

Before conversion, it helps to understand what each flag means:

Converting to JavaScript Fetch API

The native fetch() API maps cleanly to cURL flags. A POST with JSON body becomes:

fetch('https://api.example.com/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer TOKEN'
  },
  body: JSON.stringify({ name: 'Alice' })
})
.then(res => res.json())
.then(data => console.log(data));

One pitfall: fetch does not follow redirects that change the method from POST to GET by default. If the API redirects, check the redirect option.

Converting to Axios

Axios automatically serialises JavaScript objects to JSON when you set Content-Type: application/json, so you can pass the object directly to data instead of calling JSON.stringify. The converter handles this distinction for you.

Converting to Python Requests

Python's requests library is arguably the most readable target:

import requests

response = requests.post(
    'https://api.example.com/users',
    headers={'Authorization': 'Bearer TOKEN'},
    json={'name': 'Alice'}
)
print(response.json())

Note that using the json= keyword argument automatically sets the Content-Type header and encodes the body, so you do not need to specify it manually.

Common Pitfalls with Special Characters

Headers copied from terminals often contain invisible Unicode dashes or smart quotes instead of plain ASCII hyphens and straight quotes. This causes signature mismatches in APIs like AWS that sign headers. Always inspect pasted commands for these substitutions before converting.

When -d contains shell variables like $TOKEN, the converter cannot resolve them. Replace them with literal values or environment variable references in your target language before running the converted code.

The -k / --insecure Flag Warning

Many teams paste cURL commands that include -k because someone bypassed a certificate error during testing. The converter will include the equivalent insecure option in the output, but it also raises a visible warning. In Python that means verify=False; in Node.js it requires setting NODE_TLS_REJECT_UNAUTHORIZED=0. Both are dangerous in production and will expose your application to man-in-the-middle attacks.

Handling Cookies

When a cURL command uses -b to send cookies, the converter places the value directly in a Cookie header. For browser-based fetch calls, be aware that credentials: 'include' controls whether the browser sends its own cookies automatically, which is separate from manually constructed cookie strings.

Multipart Form Uploads

File upload commands using -F are translated to FormData in JavaScript or files= in Python Requests. Because the file path in the original cURL command is local to the machine where it was run, the converter replaces the file reference with a placeholder you must substitute with your actual file input.

Related Tools

After converting a command, you may want to inspect the live headers returned by the endpoint — use the HTTP Headers Checker for that. If any header values are Base64-encoded, the Base64 Encoder can decode them instantly.

🧰 50+ Tools