Convert cURL to Code - Python, JavaScript, PHP, Go
Paste a curl command and instantly get equivalent code in Python, JavaScript, Node.js, PHP, or Go. Parses headers, body, authentication, and method automatically.
Why Convert cURL to Code?
Every developer has copied a curl command from API documentation, a browser's DevTools network tab, or a colleague's Slack message. The next step is always the same: manually translating that curl command into the language your project uses. This tool eliminates that tedious translation step.
When you right-click a network request in Chrome or Firefox DevTools and select "Copy as cURL," you get a fully formed curl command with all the headers, cookies, and authentication your browser sent. Pasting that into this converter gives you production-ready code in seconds instead of minutes spent manually mapping flags to library parameters.
How the Converter Works
The converter tokenizes your curl command while respecting quoted strings, escaped characters, and backslash line continuations. It then identifies each flag and its argument:
- -X / --request: Sets the HTTP method (GET, POST, PUT, DELETE, PATCH). If omitted and -d is present, defaults to POST.
- -H / --header: Adds a request header. Multiple -H flags are supported. The converter splits on the first colon to separate the header name and value.
- -d / --data / --data-raw: Sets the request body. Automatically implies POST if no method is specified.
- -u / --user: Basic authentication in user:password format.
- -A / --user-agent: Sets the User-Agent header.
- -b / --cookie: Sets cookies via the Cookie header.
After parsing, the converter generates idiomatic code for your chosen language, using each language's standard HTTP library conventions and best practices.
Supported Languages
Python (requests)
Generates code using the requests library, the de facto standard for HTTP in Python. Outputs clean variable assignments for URL, headers, and data, followed by the appropriate requests method call. Authentication is mapped to the auth tuple parameter.
JavaScript (fetch)
Produces modern async/await code using the Fetch API, which is available in all browsers and Node.js 18+. Headers are placed in a headers object, and the body is passed as a string. No external dependencies required.
Node.js (axios)
Generates code using axios, the most popular HTTP client for Node.js. Uses the configuration object pattern with url, method, headers, data, and auth properties.
PHP (curl)
Outputs PHP code using the native curl_* functions. Maps each curl flag to the equivalent curl_setopt call. Includes proper resource cleanup with curl_close.
Go (net/http)
Generates Go code using the standard library's net/http package. Creates an http.Request, sets headers, configures authentication, and reads the response body. No external dependencies needed.
Common Use Cases
- API integration: Copy curl examples from API docs (Stripe, Twilio, AWS) and convert to your project's language.
- Debugging reproduction: Export a failing request from DevTools as curl, then convert to code for a test case.
- Learning HTTP clients: See how the same request looks across different languages and libraries.
- Code review prep: Convert a curl one-liner into readable, structured code before committing.
Tips for Best Results
- Include the full curl command including the
curlprefix. - Multi-line curl commands with backslash continuations (
\) are supported. - Both single-quoted and double-quoted strings are handled correctly.
- If your curl command contains
-H "Authorization: Bearer token123", the token will appear in the generated code. This tool runs locally, so your tokens are safe.
Frequently Asked Questions
How do I convert a curl command to Python?
Paste your full curl command into the input area and select "Python (requests)" from the language dropdown. The tool parses the URL, HTTP method, headers, request body, and authentication from your curl command and generates clean Python code using the requests library. The generated code includes proper variable assignments and is ready to copy into your project.
What curl flags does the converter support?
The converter handles the most commonly used flags: -X (HTTP method), -H (headers), -d/--data/--data-raw (request body), -u (basic auth), -A (user agent), and -b (cookies). It correctly handles quoted arguments, escaped characters, and multi-line commands with backslash continuations.
Can I convert curl to JavaScript fetch?
Yes. Select "JavaScript (fetch)" from the dropdown. The converter generates modern async/await code using the native Fetch API. It maps curl headers to the fetch headers object, the request body to the body parameter, and the HTTP method to the method option. The generated code works in all modern browsers and Node.js 18+.
Is my curl command sent to a server?
No. All parsing and code generation happens entirely in your browser using client-side JavaScript. Your curl commands, including any API keys, bearer tokens, passwords, or sensitive data, never leave your machine. There are no API calls, no logging, and no server-side processing.