cURL to Code
Convert cURL commands to executable code in JavaScript, Python, or PHP. Automatically extracts HTTP method, URL, headers, body, and authentication.Overview
The cURL to Code tool parses cURL command-line syntax and generates equivalent code for:- JavaScript (fetch API)
- Python (requests library)
- PHP (curl extension)
Use Cases
API exploration
Copy a cURL request from browser DevTools and convert it to working code for your project
Documentation samples
Generate code examples in multiple languages from a single cURL command
Testing & debugging
Quickly reproduce API requests in your language of choice
Migration
Convert legacy cURL scripts to modern HTTP client code
Supported cURL Flags
Method & URL
Method & URL
-X,--request— HTTP method (GET, POST, PUT, DELETE, etc.)- First non-flag argument — URL
Headers & body
Headers & body
-H,--header— HTTP headers (e.g.,Content-Type: application/json)-d,--data,--data-raw,--data-binary— Request body (implies POST if method not set)
Authentication
Authentication
-u,--user— Basic authentication (username:password)
Input Format
Paste a cURL command. The tool handles:- Single-line or multiline (backslash-continued) commands
- Single or double-quoted arguments
- Optional
curlprefix
Example
Output Formats
- JavaScript (fetch)
- Python (requests)
- PHP (cURL)
Generates
fetch() calls with method, headers, and body.Implementation Details
The tool tokenizes the input command, respecting shell quoting rules:- Split on whitespace, preserving quoted strings
- Extract method, URL, headers, body, and auth from flags
- Generate idiomatic code for each target language
lib/tools/curl-to-code.ts:64-124
The parser handles basic cURL syntax. Complex shell features (pipes, redirects, environment variables) are not supported.
Keyboard Shortcuts
Cmd/Ctrl+Enter— Convert to JavaScript (default)Cmd/Ctrl+Shift+C— Copy outputCmd/Ctrl+Shift+S— Download output
Related Tools
JSON to Code
Generate TypeScript/Python/Go/Rust types from JSON
URL Parser
Break down URL components and query parameters