curl → Code Converter

Convert a curl command into JS fetch, PowerShell or .NET HttpClient code.

Open tool

Overview

The curl → code converter takes a curl command — the kind you copy out of a browser's "Copy as cURL" menu or paste from API documentation — and rewrites it as equivalent code in JavaScript fetch, PowerShell Invoke-WebRequest, or .NET HttpClient. Method, URL, headers, body, query string, and authentication translate one-to-one.

Developers who reverse-engineer requests from browser DevTools, integration engineers porting a Postman collection, and anyone copy-pasting from API docs into their own codebase save the manual transcription. Long-tail keywords covered: convert curl to JavaScript fetch online, curl to PowerShell Invoke-RestMethod, and curl to C# HttpClient example.

How it works

A curl command is a sequence of flags and arguments around a URL. The parser handles the common ones — -X for method, -H for headers, -d, --data, and --data-binary for body, -u for HTTP Basic, -b and --cookie for cookies, -F for multipart form fields, and --compressed to request gzip. Shell quoting ('...', "...", line continuations with backslashes) is handled before translation.

The output preserves the original semantics where possible. JSON bodies stay as JSON; form bodies use URLSearchParams or FormData depending on the source flag. Headers are emitted in the target language's idiomatic style: an object literal for fetch, a hashtable for PowerShell, and HttpRequestMessage.Headers for .NET.

Examples

  • curl -X POST -H "Content-Type: application/json" -d '{"name":"alice"}' https://api.example.com/users translates to fetch(...) with method, headers, and body set accordingly.
  • curl -u admin:secret https://api.example.com/admin becomes fetch with an Authorization: Basic header.
  • curl --data-urlencode "q=hello world" https://search.example.com produces a URLSearchParams body or a properly encoded application/x-www-form-urlencoded payload.
  • curl -F "file=@photo.jpg" -F "caption=Sunset" https://api.example.com/upload becomes a FormData multipart upload.

FAQ

Does it support every curl flag?

The common ones — about 95% of what real-world commands use. Exotic flags like --resolve, --interface, --tlsv1.3, and proxy options are flagged as unsupported rather than silently dropped.

Why does the converted code look slightly different from the curl behaviour?

curl follows redirects by default only with -L; fetch always follows. Some defaults differ across languages. The output adds comments where behaviour might surprise you.

Can I paste a multi-line curl command?

Yes — line continuations with \ and unquoted whitespace are normalised before parsing.

Are cookies and authentication preserved?

Yes. -b/--cookie becomes a Cookie header, and -u user:pass becomes a properly encoded Authorization: Basic header.

Try curl → Code Converter

An unhandled error has occurred. Reload ×