{jsonbody.com}

cURL to Code Converter

Convert cURL commands to Python requests, JavaScript fetch or axios, PHP cURL and Go net/http. Headers, bodies, auth and form data carry over. Free and private.

Turn a cURL command into working code

API docs tend to show examples as cURL commands, and browser developer tools offer Copy as cURL on any network request. To use one in an application, it has to be rewritten in your language. This converter parses the command and writes the equivalent code using Python requests, JavaScript fetch or axios, PHP's cURL functions or Go's net/http package.

The conversion runs entirely in your browser, which matters because copied commands often contain cookies and tokens.

What is carried over

  • The method (-X), URL and query string.
  • Headers (-H), cookies (-b), the user agent (-A) and the referrer (-e).
  • Request bodies from -d, --data-raw, --data-binary, --data-urlencode and --json.
  • Basic authentication (-u) and multipart form fields (-F).
  • Flags that change behaviour, such as -L to follow redirects and -k to skip certificate checks.

Example

A POST request with a JSON body becomes a short JavaScript snippet. Choose another tab to see the same request in axios, Python, PHP or Go. Replace YOUR_TOKEN with a value loaded from your environment, rather than leaving a secret in source code.

cURL input and JavaScript output
curl -X POST 'https://api.example.com/v1/users' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{"name":"Asha"}'

const response = await fetch("https://api.example.com/v1/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN",
  },
  body: JSON.stringify({
    "name": "Asha"
  }),
  redirect: "manual", // cURL does not follow redirects without -L
});

const data = await response.text();
console.log(response.status, data);

Copying requests from the browser

In Chrome, Edge or Firefox, open developer tools, go to the Network tab, right-click a request, and choose Copy as cURL. On Windows, pick the bash or POSIX option if one is offered, because this tool reads POSIX shell quoting. Copied commands include many headers that an API usually does not need, such as sec-ch-ua. You can normally delete these from the generated code, leaving only the headers the endpoint requires.

Frequently Asked Questions

Why does the code work in Node but fail in my web page?

Browsers enforce CORS and block some headers such as Cookie. cURL and server-side code have no such limits. Call the API from your backend if the browser is blocked.

Does -d send a POST request?

Yes. Using a data flag without -X makes the request a POST, and the converter follows this behaviour. Adding -G sends the data in the query string instead.

Does the Go code need any extra packages?

No. It uses only the Go standard library, so you can paste it into a main.go file and run it. The axios version needs npm install axios, and the Python version needs pip install requests.

Which flags are ignored?

Options that only affect cURL's own output or connection, such as -o, -s and --connect-timeout, have no direct equivalent and are skipped.

Is the code safe to use with -k?

The flag turns off certificate checks, and the generated code preserves that if the language allows it. Remove it before production, because it exposes you to interception.