cURL to Code Converter
Convert a cURL command into Python, JavaScript, Go, PHP and more — with the request it makes laid out.
Converts a curl command into code for Python (requests), JavaScript (fetch), Node.js (axios), Node.js (fetch), Go, PHP (cURL), PHP (Guzzle), Java (HttpClient), C# (HttpClient), Rust (reqwest), Ruby (Net::HTTP), PowerShell, Dart (http), Swift (URLSession), Kotlin (OkHttp), HTTPie or wget, and lays out the request it makes — method, URL, query, headers, body — so you can check the command was read as you meant.
Paste a command copied from the browser's developer tools in any of its forms: Chrome's “Copy as cURL” for bash and for Windows cmd, Firefox's, or a curl.exe line from PowerShell. The code is written by curlconverter, the open-source converter. It runs in your browser: nothing you paste is sent anywhere, and the request itself is never made.
How to use it
- Language — remembered for your next visit.
- Copied from — Detect reads the quoting:
^"or a^at the end of a line is cmd,curl.exeor a backtick at the end of a line is PowerShell, anything else bash. Pick the shell when a command is read wrongly; a warning says when the quoting points to another one. Each visit starts at Detect again. - Request — the method, the URL without its query, the query parameters decoded, the headers, the body (JSON laid out, with its numbers as written) and the user of
-u. Each row copies on its own.
Notes under the command say what the language cannot express, such as -k for fetch, and what was kept as written: variables such as $TOKEN stay as text, as no shell runs here. Only the first command is read; anything after a |, ;, &, &&, || or a redirection is left out, with a note.
How curl reads a command
The method is GET, or POST once there is a body (-d, --data-raw, --json, -F); -X overrides it, -I makes it HEAD, and -G moves the data into the query of a GET. Several -d are joined with & and sent as a form; -F sends multipart form data, with @file for a file and ;type= for its type. --json sets the JSON content type and accept headers. -u user:password becomes Basic authentication, and -b a Cookie header.
A body or form field read from a file (-d @data.json, -F file=@photo.jpg) becomes code that opens the file by that name, since the file itself is not here.
Examples
A Chrome DevTools copy to Python
- cURL command
curl 'https://api.example.com/v1/orders?expand=items' \ -H 'accept: application/json' \ -H 'content-type: application/json' \ -b 'session=abc123' \ --data-raw '{"sku":"MUG-01","qty":2,"gift":false}'- Python (requests)
import requests cookies = { 'session': 'abc123', } headers = { 'accept': 'application/json', 'content-type': 'application/json', # 'cookie': 'session=abc123', } params = { 'expand': 'items', } json_data = { 'sku': 'MUG-01', 'qty': 2, 'gift': False, } response = requests.post('https://api.example.com/v1/orders', params=params, cookies=cookies, headers=headers, json=json_data) # Note: json_data will not be serialized by requests # exactly as it was in the original request. #data = '{"sku":"MUG-01","qty":2,"gift":false}' #response = requests.post('https://api.example.com/v1/orders', params=params, cookies=cookies, headers=headers, data=data)
The JSON body becomes a dictionary sent with json=, and the cookie a dictionary of its own. The tool also warns: The command holds credentials: a Cookie header. Remove them before sharing the code.
The same request copied for Windows cmd
- cURL command
curl ^"https://api.example.com/v1/orders?expand=items^" ^ -H ^"accept: application/json^" ^ -H ^"content-type: application/json^" ^ -b ^"session=abc123^" ^ --data-raw ^"^{^\^"sku^\^":^\^"MUG-01^\^",^\^"qty^\^":2,^\^"gift^\^":false^}^"- Note under the command
- Read as a Windows cmd command
Every special character carries a ^ for cmd, and the quotes inside the body a backslash for curl.exe as well. Read with both passes, it gives the same request and the same Python as the bash copy.
A file upload to JavaScript fetch
- cURL command
curl https://upload.example.com/photos \ -F 'photo=@beach.jpg;type=image/jpeg' \ -F 'caption=Sunset at the beach'
- JavaScript (fetch)
const form = new FormData(); form.append('photo', File(['<data goes here>'], 'beach.jpg')); form.append('caption', 'Sunset at the beach'); fetch('https://upload.example.com/photos', { method: 'POST', body: form });
Each -F becomes a FormData field, and fetch sets the multipart content type with its boundary itself.
Sources
Options are read as curl documents them; methods and headers as HTTP defines them, and multipart bodies by RFC 7578.
Sources
- curl man page — curl project
- RFC 9110: HTTP Semantics — IETF
- RFC 7578: Returning Values from Forms: multipart/form-data — IETF
Reviewed
Frequently asked questions
curl is a name for Invoke-WebRequest, so write curl.exe to run the real curl.-b and --oauth2-bearer set too), or a user and password from -u, -U or the URL. It cannot know about secrets elsewhere, such as an API key in the query or the body, so check those yourself.See also
- cURL Command Generator — to build a curl command from a URL, headers and a body.
- JSON Formatter & Minifier — to check and format a JSON body.