FROM A REQUEST TO WORKING CODE

cURL Converter.

Turn a curl command into a request you can use in your project. Generate JavaScript, Python or PHP — with request details and conversion notes.

curlrequest code
Browser-only conversion
01

Paste one HTTP request, including quoted headers and body data. POSIX quotes and backslash line continuations are supported.

POSTexample.com3 headers
02
async function main() {
  const response = await fetch("https://example.com/api/messages", {
    method: "POST",
    headers: [
      ["Authorization", "Bearer YOUR_TOKEN"],
      ["Content-Type", "application/json"],
      ["Accept", "application/json"]
    ],
    body: "{\"message\":\"Hello from curl\",\"enabled\":true}",
    redirect: "manual",
    credentials: "omit"
  });
  console.log(response.status);
  console.log(await response.text());
}

main().catch(console.error);

Browser Fetch or Node.js 18+

Before you run it

  • The converter does not send a request. Generated code contains the supplied URL, headers and credentials; review it before sharing.
  • Browser Fetch is subject to CORS. Cookies are not sent automatically (credentials: omit); configure browser credentials intentionally if needed. Manual redirects may produce an opaque response in a browser.

No account. No request execution. Commands are converted locally in your browser.

Move a tested curl request into your application

A curl command is a convenient way to share an API call. Turning it into application code usually means separating the URL, method, headers and body, then checking how the new HTTP client handles them. This online cURL converter does that first pass for JavaScript Fetch, Python Requests and PHP cURL.

Use it to turn a documented API example into a script, reproduce a request copied from developer tools, or compare the same request across languages. The editor converts one request at a time and explains target-specific differences before you copy the result.

How to convert curl to code

  1. Paste one complete command beginning with curl. Keep quotes around URLs containing query parameters and around headers or body values.
  2. Choose the output language. The same parsed request is used for each target.
  3. Read the conversion notes. Browser-managed headers and unsupported request combinations need particular attention.
  4. Copy the snippet or download the language-specific file. Review any credentials before saving it in a repository.
  5. Run it in the intended environment when you are ready to make the actual request.

Backslash line continuations and short forms such as -XPOST are accepted. The parser never evaluates command substitutions or reads local files. A syntax error or unsupported option withholds the output rather than exporting an incomplete request.

Convert curl to Python, JavaScript or PHP

Python Requests

The Python output uses requests.request, an explicit method, a header dictionary and UTF-8 bytes for an inline body. It is useful for API scripts and backend integrations. Install Requests first with pip install requests. No application timeout is invented by the converter; add one that suits the service you call.

JavaScript Fetch

The JavaScript output uses an async function and prints the status and response text. It can be adapted for browser code or Node.js with Fetch support. A browser cannot reproduce every header from a terminal request, so the converter lists the headers it leaves out. A request body on GET or HEAD stops Fetch conversion; choose another target or use query parameters instead.

PHP cURL

The PHP output sets options on a cURL handle, sends literal body text and checks for transport errors. It requires the PHP cURL extension. This target is useful when an existing PHP service already uses libcurl and needs the request expressed as application code.

Supported curl options

InputConversion
URL / --urlOne explicit HTTP or HTTPS URL; repeated query keys remain in the URL.
-X / --requestAn explicit method, such as POST, PUT, PATCH or DELETE.
-H / --headerA header name and value. Duplicate or empty-header directives require review.
-d / --data / --data-asciiLiteral body text; repeated values are joined with an ampersand.
--data-raw / --data-binaryInline body text. File references are not read.
--data-urlencodePercent-encodes inline values, including spaces and Unicode.
--jsonLiteral JSON body plus default JSON Content-Type and Accept headers.
-G / --getMoves supplied body data into the query string.
-u / --userBasic Auth with an explicit ASCII username:password.
-b / --cookieInline cookie data; cookie files are not loaded.
-A / --user-agent, -e / --refererHeader values, with browser restrictions noted for Fetch.
-L / --locationEnables redirect following; target-library rules still apply.
-I / --headA HEAD request with header-oriented output.
-k / --insecureDisables TLS verification in Python and PHP; unavailable in Fetch.
--compressedUses the target runtime’s decompression support.
-s, -S, -v, -iRecognized display flags; terminal formatting is not reproduced.

Example: curl to a Python POST request

An inline form can contain repeated fields without becoming a dictionary. The converter keeps the encoded body as a string and passes UTF-8 bytes to Requests:

curl 'https://example.com/api/tags' \
  --data-urlencode 'tag=cloud hosting' \
  --data-urlencode 'tag=linux'
import requests

response = requests.request(
    "POST",
    "https://example.com/api/tags",
    headers={"Content-Type": "application/x-www-form-urlencoded"},
    data="tag=cloud%20hosting&tag=linux".encode("utf-8"),
    allow_redirects=False,
)
print(response.text)

Why browser code can behave differently

A successful terminal request does not establish that a browser is allowed to read the same response. CORS is enforced by the browser, and several request headers are controlled by the user agent. See the Fetch guide for browser request behavior.

The generated Fetch snippet explicitly omits automatic credentials. It also uses manual redirects unless the input includes -L. In a browser, a manual redirect can produce an opaque response. For all targets, redirect method rewriting and credential forwarding deserve review when a redirect chain is involved.

The snippets focus on the request fields supplied in the command. They do not clone a browser session or reproduce curl’s terminal progress display. Defaults such as user-agent strings, proxy environment variables and supported compression algorithms depend on the runtime. Refer to the curl manual, Requests API and PHP cURL documentation when extending the generated code.

cURL converter FAQ

Is this cURL converter free?

Yes. Convert a command, change the output language, and copy or download the snippet without an account. Conversion runs in your browser.

Does pasting a command send the HTTP request?

No. The converter parses text and generates code. It does not contact the destination, test credentials or run the generated snippet. Running the downloaded code is a separate action.

Can I paste “Copy as cURL” from developer tools?

Yes, for a single HTTP or HTTPS request using POSIX shell quoting and supported flags. Choose a bash-style export. PowerShell, CMD and ANSI-C dollar quoting are not supported. A copied browser request can contain headers that Fetch is not allowed to set; those omissions are listed explicitly.

Why does curl work while browser Fetch fails?

Browser requests are subject to CORS and browser-managed headers. Cookies and redirect responses can also behave differently. The generated Fetch code uses credentials: omit; configure credentials intentionally if the application needs them. Python and PHP execute outside browser CORS enforcement.

Are JSON values reserialized?

No. Literal JSON body text is preserved as text rather than reconstructed as a JavaScript or Python object. This keeps number spelling, whitespace and repeated JSON keys. The --json option supplies JSON headers but does not validate the payload.

Can I convert uploads, proxies or shell variables?

File uploads, multipart forms, file-backed bodies, stdin, proxy options and timeouts currently require manual configuration. Shell variables and command substitutions must be resolved before conversion. Unsupported options stop output instead of disappearing silently.

Is the generated code an exact replacement for every curl feature?

No. The supported request fields are mapped, but runtime defaults, compression, redirects, environment settings and response printing can differ. Read the conversion notes and test in the intended runtime before integrating the snippet.