araç köşesi

Convert curl Commands to Code

Turn a curl command copied from your browser or an API doc into PHP, Python (requests) or JavaScript (fetch) code

Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.

How it works

API documentation and the browser's "Copy as cURL" command both hand you requests as curl commands; this tool turns that command into code you can paste into your own program. Take curl -X POST https://api.example.com/v1/orders with the header -H "Content-Type: application/json" and the body -d '{"product": "notebook", "quantity": 2}': with Python selected you get url, headers and data variables and a requests.post(url, headers=headers, data=data) call; in PHP the same request becomes CURLOPT_HTTPHEADER and CURLOPT_POSTFIELDS inside curl_setopt_array. Trailing backslashes (\), single and double quotes, $'…' strings and the ^ escapes of the Windows cmd form are decoded from the command itself, so you do not need to clean it up first. -u user:password becomes authentication, -F fields become multipart form data, -G moves the data into the query string, -k turns off certificate checks and -m sets a timeout. Options that do not change the request, such as -s, -v and -o, are skipped and listed in the note. The conversion runs inside your browser; the passwords, cookies and access tokens in the command are never sent to any server.

This tool is also known as curl to php, curl to python, curl converter, curl to python requests, curl to fetch, curl to javascript, copy as curl to code.

What is cURL?

cURL is a free command-line program that sends requests to web addresses; the name stands for "client URL". It ships with Windows 10, macOS and Linux. API documentation gives example requests as curl commands because one line shows the address, the method, the headers and the data. PHP's cURL extension is built on the same libcurl library, which is why the PHP output maps option for option.

What is HTTP header?

An HTTP header is a name-value line sent alongside the request body: Content-Type states the body's format, Authorization carries credentials and Accept names the response type you expect. In a curl command each header is written as -H "Name: value". In code it becomes an array entry in PHP, a dictionary key in Python and a property of the headers object in fetch, with name and value carried over unchanged.

Three things curl does without being told — and why the code has extra lines

curl quietly does a few things the command never spells out. When you pass data with -d it switches the method to POST and, if there is no Content-Type header, adds Content-Type: application/x-www-form-urlencoded. Python requests and fetch do not: requests sends a text body with no type at all and fetch labels it text/plain. The server may read the same request differently, so the tool writes that header into the code explicitly, and the note shows the header count so the extra line does not surprise you.

The second difference is redirects. Without -L, curl does not follow a 301 or 302 response; requests and fetch follow them by default. A command copied from the browser usually lacks -L even though the browser did follow the redirect, so the Python and JavaScript output gets no extra setting, while the PHP output only gets CURLOPT_FOLLOWLOCATION when -L is present. The third is data from a file: -d @data.txt strips the line breaks from the file, --data-binary @data.txt keeps them, and the tool carries that distinction into the code.

fetch running in a browser has one more limit: the browser manages headers such as Cookie, Referer and User-Agent itself and ignores values set from code. The same code does send them in Node.js 18 and later. If your command contains such a header, the note warns you.

Which language to choose and where to copy the command from

Choose the language your project is written in; all three outputs send the same request. The Python requests library is installed with pip install requests; the PHP output uses PHP's own cURL extension, which most hosting plans enable; fetch needs no installation in the browser or in Node.js 18 and later.

To repeat a request a website makes, open Developer Tools with F12 in Chrome, Edge or Firefox, right-click the request on the Network tab and choose "Copy as cURL". On Windows you see two entries, "(bash)" and "(cmd)"; this tool reads both. The copied command contains your session cookie and access token, so delete those values before sharing the code with anyone.

  • Server-side PHP site or WordPress plugin → PHP (cURL)
  • Script, scraping or automation → Python (requests)
  • Web page or Node.js app → JavaScript (fetch)

Frequently asked questions

How do I convert a curl command to Python?

Paste the command into the box and choose Python. Headers go into a headers dictionary, the body into a data variable and -u credentials into the auth argument, and the request is sent with requests.post or requests.get. Install the library with pip install requests before running the code.

How do I convert curl to PHP?

Choose PHP. The output uses curl_init and curl_setopt_array: the address becomes CURLOPT_URL, the headers CURLOPT_HTTPHEADER and the body CURLOPT_POSTFIELDS. Files sent with -F become new CURLFile(…) entries.

Does a command from "Copy as cURL (cmd)" work?

Yes. The ^" escapes and the trailing ^ characters of the Windows cmd form are decoded and the command is read like the bash form. "Copy as PowerShell" produces an Invoke-WebRequest command, which is not curl, so this tool does not read it.

Are the passwords and cookies in my command sent anywhere?

No. The conversion happens entirely in your browser; the command and the passwords, cookies and tokens inside it never reach a server. If you share the resulting code, remove those values yourself first.

What does the "unknown options" note mean?

The tool converts the curl options that affect the request. When it meets an option it does not know, it skips it and names it in the note, so you can add its equivalent to the code yourself. Options that only change curl's screen output, such as -s, -v and -o, are skipped too.