cURL to code — convert a curl command to fetch, axios, Python, PHP or Go

Paste a curl command, for example one copied from API docs or from your browser's network panel, and the tool rewrites it as JavaScript fetch, axios, Python requests, PHP cURL or Go net/http code with the same method, headers, body and authentication.

Live demo · real result from this tool

Code

const response = await fetch("https://api.example.com/v1/orders", {  method: "POST",  headers: {    "Content-Type": "application/json",    "Authorization": "Bearer YOUR_TOKEN",  },  body: JSON.stringify({    "item": "book",    "qty": 2  }),  redirect: "manual", // curl does not follow redirects without -L});const data = await response.json();console.log(response.status, data); 

Parsed request

PartValue
MethodPOST
URLhttps://api.example.com/v1/orders
Header: Content-Typeapplication/json
Header: AuthorizationBearer YOUR_TOKEN
Body{"item":"book","qty":2}

The command includes credentials (Authorization or Cookie). Keep real tokens out of code you share or commit.

Processed on your device — nothing is uploaded.

How to use cURL to Code

  1. Paste the command into curl command. It must start with curl (or curl.exe). Multi-line commands with \ at the line ends are fine.
  2. Choose a language in Convert to: JavaScript — fetch, JavaScript — axios, Python — requests, PHP — cURL or Go — net/http.
  3. Copy or download the code (request.js, request.py, request.php or main.go).
  4. Check the Parsed request table and the notes. Options the tool did not convert are listed there, so nothing is dropped silently.

What it does and when to use it

API docs usually give curl examples, and the browser can copy any request as curl. Turning one into application code by hand is slow and easy to get wrong, especially quoting, form encoding and auth. This tool does that translation for one request at a time.

It understands the options people use most: -X, -H, -d and its variants, --data-urlencode, --json, -F multipart uploads, -u basic auth, --oauth2-bearer, -A, -e, -b cookie strings, -G, -I, -L, -k, --compressed, -m and bundled flags such as -sSL or -XPOST. To go the other way, from fields to a command, use the cURL Builder.

How it works

The command is first split into words the way a POSIX shell would: single quotes, double quotes, $'…' strings and backslash continuations, with no variable expansion. curl’s options are then read into one request: method, URL, headers, body and auth. As in curl, a body without -X makes the method POST, and a body with no Content-Type header is sent as application/x-www-form-urlencoded. A JSON body becomes a real object in the generated code (JSON.stringify, json= in Python) when it parses as JSON.

Worked examples

A GitHub API call in Python. curl https://api.github.com/repos/octocat/hello-world -H "Accept: application/vnd.github+json" gives a headers dict and:

response = requests.get("https://api.github.com/repos/octocat/hello-world", headers=headers, allow_redirects=False)

curl –json to axios. curl --json '{"name":"Ana"}' https://x.io/users sets the method to post, adds Content-Type and Accept: application/json, and passes the body as an object:

  data: {
    "name": "Ana"
  },

A GET with encoded parameters. curl -G https://x.io/search --data-urlencode "q=red shoes" -d limit=5 -k moves the data into the URL. The fetch output starts with a comment that -k cannot be copied, then:

const response = await fetch("https://x.io/search?q=red%20shoes&limit=5", {
  redirect: "manual", // curl does not follow redirects without -L
});

Limits and tips

  • One request per command. Pipes, &&, $VAR values and config files (-K) are not run or expanded.
  • File uploads (-F file=@photo.jpg) become placeholders such as fileInput.files[0] in JavaScript; point them at your real file.
  • A URL without a scheme gets http://, as curl does.
  • To decode a Basic auth header found in a command, use the Basic Auth Generator. To read a long URL from the command, use the URL Parser.

Frequently asked questions

Does "Copy as cURL" from Chrome or Firefox work?
Yes. Both the bash version and Chrome's Windows "Copy as cURL (cmd)" version are read, including ^ escapes and line continuations. Browser copies include many headers, such as cookies and sec-ch-ua; delete the ones your code does not need.
Why does the Python code say allow_redirects=False?
curl does not follow redirects unless you pass -L, so the generated code keeps that behaviour. Add -L to the command if you want redirects followed. The fetch code sets redirect to manual for the same reason. In a browser that gives an opaque response for a redirect, so add -L if you need the final page.
What happens to -d @data.json?
A body read from a file cannot be included, so the tool lists a note asking you to paste the file contents into the command instead.
Is my token sent anywhere?
No. The command is parsed and the code is generated in your browser. The tool shows a warning when the command has an Authorization or Cookie header, so you remember not to commit it.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close