Convert a curl command to Python, JavaScript, Node.js, Go, Java, Kotlin, PHP, C#, Swift, PowerShell and more, or HTTPie, Wget or HAR
Paste a curl command and get the same request as a short program for 41 clients in 23 languages, from Python and Node.js to Kotlin, Swift and PowerShell, or as an HTTPie or Wget command or a HAR file, with a note for anything the client can’t repeat.
How to use it
Paste a curl command or open a file with one. A browser’s Copy as cURL works as it is, from bash or Windows cmd. Pick the language and client. The program sends the request once and prints the status and the body. No command at hand? Pick an Example under Options (GET, form, JSON, basic auth, file upload). Copy or download the code. Notes above it name any option the client can’t repeat.
Examples
A JSON POST copied from the browser, in Python
curl 'https://api.example.com/v1/orders' -H 'content-type: application/json' --data-raw '{"sku":"A-1","qty":2}'import requests
headers = {
'content-type': 'application/json',
}
data = '{"sku":"A-1","qty":2}'
response = requests.post(
'https://api.example.com/v1/orders',
headers=headers,
data=data,
)
print(response.status_code)
print(response.text)Language: Python (requests). Data makes it a POST, as curl does.
A login and a query, in JavaScript
curl -u ada:hunter2 -G -d q=coffee -d page=2 https://api.example.com/search
const response = await fetch('https://api.example.com/search?q=coffee&page=2', {
headers: {
'Authorization': 'Basic ' + btoa('ada:hunter2'),
},
});
console.log(response.status);
console.log(await response.text());Language: JavaScript (fetch). -G moves the -d data into the URL, and -u becomes an Authorization header.
A Windows copy (cmd), in PHP
curl ^"https://api.example.com/v1/me^" ^ -H ^"accept: application/json^" ^ --compressed
<?php
$ch = curl_init('https://api.example.com/v1/me');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'accept: application/json',
],
CURLOPT_ENCODING => '',
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n";
echo $response, "\n";Language: PHP (curl). The ^ escapes and line ends are read as cmd reads them; --compressed becomes CURLOPT_ENCODING.
What a client can’t repeat is named
curl -k -x proxy.local:8080 https://api.example.com/v1/report
fetch can’t skip the certificate check (-k): the request fails if the certificate isn’t valid. fetch has no proxy setting (-x), so the proxy is left out.
Language: JavaScript (fetch). These notes show above the code. Java can’t repeat -k either; Python, Go, PHP, C#, Ruby and Rust repeat both options.
A JSON POST in PowerShell
curl https://api.example.com/v1/items --json '{"name":"Notebook","price":4.5}'$headers = @{
'Accept' = 'application/json'
}
$response = Invoke-RestMethod `
-Uri 'https://api.example.com/v1/items' `
-Method 'POST' `
-Headers $headers `
-Body '{"name":"Notebook","price":4.5}' `
-ContentType 'application/json' `
-MaximumRedirection 0 `
-SkipHttpErrorCheck `
-StatusCodeVariable status
$status
$responseLanguage: PowerShell (Invoke-RestMethod), PowerShell 7. --json sets both headers; redirects stay unfollowed and a 4xx is printed, as curl does without -L and -f.
A file upload in Node.js with axios
curl https://example.com/upload -F 'title=Holiday' -F 'photo=@beach.jpg;type=image/jpeg'
import { openAsBlob } from 'node:fs';
import axios from 'axios';
const form = new FormData();
form.append('title', 'Holiday');
form.append('photo', await openAsBlob('beach.jpg', { type: 'image/jpeg' }), 'beach.jpg');
const response = await axios('https://example.com/upload', {
method: 'POST',
data: form,
maxRedirects: 0,
responseType: 'text',
validateStatus: () => true,
});
console.log(response.status);
console.log(response.data);Language: Node.js (axios). -F builds a multipart form; the file is read from disk when the program runs (Node.js 20 or later).
Where to get a curl command
What is read
Method and URL: -X, --url, --url-query, -G, -I, and a POST when there is data. Headers: -H, -A (user agent), -e (referer), -b (cookies), -u (basic login), --oauth2-bearer. Body: -d, --data-raw, --data-binary, --data-urlencode, --json, -F for a multipart form (files included), and -T to send a file. Settings: -k (skip the certificate check), -L (follow redirects), -m (time limit), -x (proxy), --compressed.
The languages and clients
JavaScript: fetch (browser or Node.js 18+), XMLHttpRequest and jQuery for a page; Node.js: axios, got, ky, node-fetch, superagent and the built-in http module. Files in the body need Node.js 20 or later. Python: requests (pip install requests) or http.client from the standard library. Java: HttpClient (Java 11+), HttpURLConnection, OkHttp or jsoup; Kotlin with OkHttp; Clojure with clj-http. PHP: the curl extension or Guzzle. Ruby: Net::HTTP or HTTParty. Perl: LWP. Lua: LuaSocket with LuaSec. R: httr2. Go: net/http. Rust: reqwest with its "blocking" feature. C: libcurl. C#: HttpClient (.NET 6+). Swift and Objective-C: URLSession. Dart: package:http. Elixir: Req. OCaml: cohttp-lwt-unix. Julia: HTTP.jl. MATLAB: matlab.net.http. PowerShell 7: Invoke-RestMethod or Invoke-WebRequest. Commands: HTTPie and Wget. Files: a HAR 1.2 log, or the request as plain JSON.
Questions
- Does the page send my request?
No. It only writes the code. The request goes out when you run the program yourself. - Why are Content-Length and Accept-Encoding left out?
A copied Content-Length is wrong as soon as the body changes, and a copied Accept-Encoding can make the response arrive compressed to a client that only unpacks what it asked for itself. Each client writes these headers on its own, and a note says when they were left out. - What happens to $VARIABLES in the command?
They are written as they are, not filled in, and a note lists them. Replace them in the code with the values you use. - Can I import the request into Postman, Insomnia or a browser?
Pick HAR file as the language: it writes the request as a HAR 1.2 log, which Postman, Insomnia and the browsers’ developer tools import. JSON writes the same parts as plain JSON for your own scripts. - Why does the code turn off retries and redirects?
curl sends a request once and follows a redirect only with -L. Clients such as got, ky, Req and OkHttp retry or follow redirects on their own, so the code sets them to do what the command did. - Is my command uploaded?
No. Everything runs in your browser, so your command stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. Copied commands often hold tokens and passwords, and the page warns you if it spots one.