Skip to content
ToolkitHub

cURL Command Converter

Convert cURL to Fetch, Axios, Python

Guide

From cURL commands to application code

By Logappradeep · ServiceNow developer

cURL is the universal language of HTTP examples. API documentation, browser DevTools ("Copy as cURL"), Postman and support tickets all express requests as curl commands. The command is perfect for a quick terminal test, but your application needs the same request in JavaScript or Python. This converter reads the command and writes an equivalent snippet so you do not have to translate flags by hand.

What gets extracted

The converter recognizes the parts of a command that define most API calls:

  • The URL, quoted or unquoted, starting with http:// or https://.
  • The method from -X, such as -X PUT. If there is no -X, it uses POST when a -d body is present and GET otherwise, which mirrors cURL's own behavior.
  • Every header passed with -H "Name: value".
  • The request body passed with -d.

For example, curl -X POST "https://api.example.com/items" -H "Content-Type: application/json" -d '{"name":"pen"}' becomes a fetch() call with method: "POST", a headers object, and the body wrapped in JSON.stringify(). Choose Axios to get an axios({ method, url, headers, data }) call, or Python (Requests) to get requests.post(url, headers=headers, json=data).

Typical workflow

  1. In the browser's Network panel, right-click a request and copy it as cURL.
  2. Paste it here and pick your target language.
  3. Drop the snippet into your code and replace hard-coded values with variables.

Limitations and pitfalls

The converter supports the short flags -X, -H and -d. Long forms like --header and --data-raw, basic auth with -u, multipart uploads with -F, cookies with -b and flags like -k or --compressed are not translated, so add those manually. Commands copied from DevTools often use --data-raw; change it to -d before pasting. The body is expected to be JSON; form-encoded bodies such as a=1&b=2 need adjusting.

Know the behavioral differences between clients, too. fetch() only rejects on network errors, not on HTTP 4xx or 5xx responses, so check response.ok. Axios rejects on non-2xx statuses by default. Python's json= argument serializes the body and sets the Content-Type header for you.

Copied commands frequently include live Authorization tokens and session cookies. The conversion runs in your browser and nothing is sent to a server, but the last command is stored in local storage, so clear the input when you finish if it contains secrets, and never commit real tokens to a repository.

Frequently asked questions

Which cURL flags are supported?

The URL plus the short flags -X, -H and -d. Other options such as -u, -F, -b, --data-raw and --header need to be added to the generated code manually.

Why does my DevTools cURL command not convert the body?

Browsers usually export bodies with --data-raw. Replace it with -d and the body will be picked up.

Why does fetch not throw on a 404 response?

fetch() resolves for any HTTP response and only rejects on network failure. Check response.ok or response.status before parsing the body.

Is it safe to paste commands with API tokens?

The conversion happens in your browser and nothing is uploaded, but the input is saved in local storage. Clear it afterward and rotate any token you may have shared elsewhere.