Boneyard Tools

curl to code: fetch and Python converter

Paste a curl command and instantly get equivalent JavaScript fetch and Python requests code. The parser reads the URL, method, headers and request body, then writes idiomatic snippets you can copy straight into your project.

How to convert a curl command

  1. Paste your curl command into the input box (or load the sample).
  2. Read the generated code in the JavaScript and Python tabs.
  3. Copy the snippet you need with the Copy button.

Examples

Simple GET

curl https://api.example.com
const res = await fetch("https://api.example.com", {
  method: "GET",
});
const data = await res.json();
console.log(data);

POST with JSON body

curl -X POST -H "Content-Type: application/json" -d '{"name":"Ada"}' https://api.example.com/users
response = requests.request("POST", "https://api.example.com/users", headers=headers, data=data)

Frequently asked questions

What does this tool do?

It turns a curl command into runnable JavaScript fetch code and Python requests code. It reads the URL, HTTP method, headers and request body from the command and writes equivalent snippets for each language.

Which curl flags are supported?

The URL (with or without a scheme), the method via -X or --request, repeatable headers via -H or --header, and the request body via -d, --data, --data-raw, --data-binary or --data-ascii. Common boolean and auth flags such as -L, -s, -k, -A and -u are recognized and skipped so they do not get mistaken for the URL.

Is my curl command sent anywhere?

No. Parsing and code generation run entirely in your browser. Nothing you paste is uploaded or stored on a server.

How is the HTTP method decided?

If you pass -X or --request, that method is used. Otherwise the tool defaults to POST when a request body is present and GET when it is not, matching how curl itself behaves.

What is the difference between fetch and requests?

fetch is the built-in HTTP client in modern browsers and Node.js and returns promises, so the snippet uses await. requests is a popular Python library you install with pip; the snippet uses requests.request(method, url, headers=..., data=...).

Does it handle headers and JSON bodies with quotes?

Yes. The tokenizer respects single and double quotes and backslash escapes, so headers like Authorization: Bearer token and JSON bodies with quoted keys are parsed and re-escaped correctly in the generated code.

Related tools