Skip to main content

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)
Supports multiline commands (with backslash continuations), quoted arguments, and common cURL flags.

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

  • -X, --request — HTTP method (GET, POST, PUT, DELETE, etc.)
  • First non-flag argument — URL
  • -H, --header — HTTP headers (e.g., Content-Type: application/json)
  • -d, --data, --data-raw, --data-binary — Request body (implies POST if method not set)
  • -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 curl prefix
Example
curl -X POST https://api.example.com/users \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer token123' \
  -d '{"name":"Alice","email":"alice@example.com"}'

Output Formats

Generates fetch() calls with method, headers, and body.
const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer token123",
  },
  body: '{"name":"Alice","email":"alice@example.com"}',
});
const data = await response.json();

Implementation Details

The tool tokenizes the input command, respecting shell quoting rules:
  1. Split on whitespace, preserving quoted strings
  2. Extract method, URL, headers, body, and auth from flags
  3. Generate idiomatic code for each target language
Source: 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 output
  • Cmd/Ctrl+Shift+S — Download output

JSON to Code

Generate TypeScript/Python/Go/Rust types from JSON

URL Parser

Break down URL components and query parameters