DevBolt
Processed in your browser. Your data never leaves your device.

How do I convert a cURL command to code?

Paste a cURL command and instantly get equivalent code in JavaScript (fetch/axios), Python (requests), Go, PHP, Ruby, and Java. The tool parses headers, data payloads, authentication, and all common cURL flags. Everything runs in your browser — your requests are never sent to a server.

cURL to JavaScript fetch
Input
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alice"}'
Output
const res = await fetch(
  "https://api.example.com/users",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ name: "Alice" }),
  }
);
← Back to tools

cURL to Code Converter

Paste a cURL command and instantly convert it to JavaScript, Python, Go, PHP, Ruby, or Java code.

About cURL to Code

  • Paste any cURL command from browser DevTools, API docs, or your terminal — it converts to working code instantly.
  • Supports common flags: -X -H -d -u -F -L -k and more.
  • Line continuations (\) are handled automatically — paste multi-line commands directly.
  • Everything runs in your browser — no data is sent over the network.

Tips & Best Practices

Pro Tip

Use -v (verbose) to debug request/response headers

curl -v shows the full HTTP conversation: DNS resolution, TLS handshake, request headers, response headers, and body. Lines prefixed with > are sent, < are received, * are connection info. For HTTPS debugging, this reveals certificate issues, redirect chains, and header mismatches that -i alone doesn't show.

Common Pitfall

Shell quoting differs between Bash, Zsh, and PowerShell

curl -H 'Content-Type: application/json' works in Bash but fails in PowerShell (which uses different quoting). Windows cmd uses double quotes only. When converting cURL commands, always consider the target shell. Use -H "Content-Type: application/json" for maximum cross-platform compatibility.

Real-World Example

Extract cURL commands from browser DevTools

In Chrome/Firefox/Edge DevTools Network tab: right-click any request → Copy → Copy as cURL. This captures the exact headers, cookies, and authentication the browser sent. Paste it into DevBolt's converter to get equivalent Python, JavaScript, Go, or PHP code with all headers preserved.

Security Note

cURL commands in documentation often contain real credentials

Developers frequently paste cURL commands with Bearer tokens, API keys, or Basic auth into Slack, GitHub issues, and Stack Overflow. These credentials are harvestable by bots. Always replace real credentials with placeholders (YOUR_API_KEY) before sharing. Use environment variables: curl -H "Authorization: Bearer $API_KEY".

Frequently Asked Questions

How do I convert a cURL command to JavaScript fetch?
Paste your cURL command into DevBolt's converter and select JavaScript as the target language. The tool maps cURL options to fetch API parameters: the URL becomes fetch's first argument, -X maps to the method option, -H headers become entries in the headers object, and -d data becomes the body parameter. Authentication flags like -u are converted to an Authorization header with base64-encoded credentials. The converter handles most common cURL options used in API documentation and generates clean, ready-to-use code.
What cURL options are supported in code conversion?
DevBolt's converter handles the most common cURL options: -X/--request for HTTP method, -H/--header for custom headers, -d/--data for request body, -u/--user for basic authentication, -b/--cookie for sending cookies, -L/--location for following redirects, -k/--insecure for skipping SSL verification, -F/--form for multipart form data, --data-urlencode for URL-encoded payloads, and -A/--user-agent for the User-Agent header. The converter supports output in multiple languages including JavaScript (fetch and axios), Python (requests), Go, PHP, Ruby, and more.
How do I handle authentication when converting cURL to code?
The -u flag in cURL maps to language-specific auth mechanisms. For Python requests, it becomes the auth parameter tuple. For JavaScript fetch, it converts to a base64-encoded Authorization header. Bearer token authentication using -H Authorization: Bearer TOKEN converts directly to headers in all languages. DevBolt's converter generates idiomatic code for each target language, using the conventions and popular HTTP libraries of that ecosystem. Always review the generated authentication code to ensure secrets are loaded from environment variables rather than hardcoded in source code.

Related Convert Tools