liminfo

cURL Converter

Free web tool: cURL Converter

import requests

headers = {
    "Content-Type": "application/json"
}

response = requests.post(
    "https://api.example.com/data",
    headers=headers,
    data='{"key":"value"}'
)
print(response.text)

About cURL Converter

The cURL Converter is a free online tool that transforms cURL commands into equivalent source code in Python (requests), JavaScript (fetch), Go (net/http), and PHP (curl). It is designed for developers who copy cURL commands from browser DevTools, API documentation, or terminal sessions and need production-ready code in their preferred programming language.

This tool parses cURL command-line syntax including HTTP methods (-X), custom headers (-H), request bodies (-d/--data/--data-raw), and basic authentication (-u). The generated code includes proper header configuration, request body handling, and authentication setup for each target language, following each language's idiomatic HTTP client patterns.

All parsing and code generation happens entirely in your browser. Your cURL commands, which may contain API keys, authentication tokens, or internal endpoint URLs, are never sent to any server. This makes it safe to use with production API calls and sensitive credentials.

Key Features

  • Convert cURL to Python using the requests library with headers dict, data payload, and auth tuple
  • Convert cURL to JavaScript using the native fetch API with proper method, headers, and body options
  • Convert cURL to Go using net/http with NewRequest, Header.Set, and io.ReadAll patterns
  • Convert cURL to PHP using curl_init, curl_setopt, and curl_exec with proper option constants
  • Automatic HTTP method detection: defaults to POST when a request body (-d) is present
  • Full cURL flag parsing: -X (method), -H (headers), -d/--data/--data-raw (body), -u (basic auth)
  • Syntax-highlighted output with language-appropriate code formatting via PrismJS
  • One-click copy button to transfer generated code directly to your clipboard

Frequently Asked Questions

What is cURL?

cURL (Client URL) is a command-line tool for transferring data using various network protocols, most commonly HTTP and HTTPS. It is pre-installed on macOS, Linux, and Windows 10+. Developers use cURL to test APIs, download files, and debug HTTP requests. A typical cURL command looks like: curl -X POST "https://api.example.com/data" -H "Content-Type: application/json" -d '{"key":"value"}'.

How do I copy a cURL command from Chrome DevTools?

In Chrome, open DevTools (F12), go to the Network tab, and find the request you want to replicate. Right-click on the request, select "Copy" then "Copy as cURL". This copies the complete cURL command with all headers, cookies, and request body. Paste it into this tool to convert it to your preferred programming language. Firefox and Edge offer the same feature in their network inspectors.

What programming languages are supported?

This tool supports four languages: Python (using the requests library, the most popular Python HTTP client), JavaScript (using the native fetch API available in browsers and Node.js 18+), Go (using the standard library net/http package), and PHP (using the built-in curl extension). Each conversion follows the idiomatic patterns of that language.

How does the tool handle authentication?

When a cURL command includes -u or --user flags (e.g., -u username:password), the tool converts this to the appropriate authentication mechanism in each language. Python uses the auth=(user, password) tuple in requests, JavaScript adds an Authorization header with Base64 encoding, Go sets the request header, and PHP uses CURLOPT_USERPWD. This covers HTTP Basic Authentication.

Can I convert POST requests with JSON bodies?

Yes. When your cURL command includes -d or --data with a JSON string (e.g., -d '{"key":"value"}') and a Content-Type: application/json header, the tool preserves both the header and body in the generated code. The HTTP method is automatically set to POST if -d is present and no explicit -X flag is specified.

Does the tool handle multi-line cURL commands?

Yes. The parser handles backslash-newline line continuations (\) that are common when cURL commands are split across multiple lines in documentation or terminal output. The tool joins these lines before parsing, so you can paste multi-line cURL commands directly from documentation without manual editing.

Why would I convert cURL to code instead of using cURL directly?

While cURL is excellent for quick testing, production applications need HTTP calls embedded in application code with error handling, retry logic, response parsing, and integration with the rest of the codebase. Converting cURL to code gives you a working starting point that includes the exact headers, authentication, and payload from your tested request, which you can then extend with error handling and business logic.

How are custom headers handled in the conversion?

Each -H or --header flag in the cURL command is parsed into a key-value pair and translated to the target language's header syntax. Python uses a headers dictionary, JavaScript includes headers in the fetch options object, Go calls req.Header.Set() for each header, and PHP passes an array to CURLOPT_HTTPHEADER. All header values are preserved exactly as specified in the original cURL command.