cURL to fetch and Python converter
Convert a curl command into JavaScript fetch or Python requests code.
Runs in your browser. Your input is not uploaded.
What it does
API docs usually give examples as curl commands. This converter reads the command and writes the same request as JavaScript fetch or Python requests, including headers, body, form fields and basic auth.
Shell quoting and \ line continuations are handled, so you can paste a multi-line command from documentation or from the browser’s “Copy as cURL”.
How to use it
- Paste a curl command.
- Choose fetch or Python.
- Copy the code. Options that have no equivalent are listed under it.
Example
Input
curl -X POST https://api.example.com/items -H 'Content-Type: application/json' -d '{"name":"a"}'Output
const response = await fetch("https://api.example.com/items", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"name": "a"
}),
});Things to watch for
- curl does not follow redirects unless
-Lis given.fetchalways follows them, and the Python output setsallow_redirects=Falseto match curl. - Browser “Copy as cURL” includes cookies and auth headers. Remove them before sharing the code.
-k(skip TLS verification) becomesverify=Falsein Python and cannot be done with fetch.
Questions
- Which curl options are supported?
-X,-H,-dand its variants,--json,-F,-u,-G,-I,-L,-k,-A,-eand-b. Others are listed as ignored.- Is the command sent anywhere?
- No. It is parsed in this page, so tokens in it stay on your machine.
- Does it handle Windows cmd syntax?
- No. It reads POSIX shell quoting. Use the bash version of “Copy as cURL”.
- Why does -d make it a POST?
- curl switches to POST when data is given without
-X. The converter does the same.