PureDevTools

Fetch to cURL Converter

Paste a JavaScript fetch() call and get an equivalent cURL command — instantly

All processing happens in your browser. No data is sent to any server.

The URL must be a string literal. Variable references, template literals with expressions, and dynamic headers are not resolved. For multipart/form-data bodies, use --form flags manually.

You wrote a fetch() call in JavaScript and now you need to share it with a teammate, paste it into a terminal to debug, add it to API documentation, or reproduce it in a CI script. Converting fetch() to cURL by hand means manually mapping every header, body, and option — error-prone and slow. This tool does it instantly.

Why Convert fetch() to cURL?

Debugging. cURL runs in any terminal without a Node.js runtime. Paste the converted command into your shell to verify the request reaches the server exactly as intended, without executing your full application.

Sharing and documentation. cURL is the universal language of HTTP examples. API documentation, Stack Overflow answers, GitHub issues, and Postman collections all use cURL. Converting your fetch() call makes it instantly reproducible by anyone, regardless of their language or toolchain.

CI/CD and scripting. Shell scripts in pipelines often call APIs with cURL. Converting a fetch() call from your frontend code gives you a tested, equivalent shell command ready to paste.

Reverse-engineering. If you inherited a codebase and want to understand what a fetch() call does at the HTTP level, seeing the equivalent cURL command makes every header, method, and body explicit.

Supported fetch() Patterns

The converter handles the most common fetch() usage patterns:

Method and URL

fetch("https://api.example.com/endpoint", { method: "POST" })
// → curl -X POST 'https://api.example.com/endpoint'

Custom headers

fetch(url, {
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer token123"
  }
})
// → curl ... -H 'Content-Type: application/json' -H 'Authorization: Bearer token123'

JSON body via JSON.stringify()

fetch(url, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ key: "value", count: 42 })
})
// → curl -X POST ... -H 'Content-Type: application/json' -d '{"key":"value","count":42}'

Follow redirects

fetch(url, { redirect: "follow" })
// → curl -L ...

Output Format

The generated cURL command uses:

Example output for a POST request:

curl -X POST 'https://api.example.com/users' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer my-token' \
  -d '{"name":"Alice","role":"admin"}'

Limitations

String literal URLs only. The parser requires the URL to be a string literal ("...", '...', or a plain backtick string). Variable references like fetch(apiUrl, ...) cannot be resolved at parse time.

Inline options object only. The options argument must be an inline object literal. If you store options in a variable first (const opts = {...}; fetch(url, opts)), the tool cannot follow the variable reference.

No multipart/form-data. If your body is a FormData object, the tool cannot reconstruct the multipart boundaries. Add --form flags manually for file uploads.

No dynamic header values. Template literals like `Bearer ${token}` in header values are not evaluated.

Relationship to cURL to Code

This tool is the reverse of our cURL to Code Converter. That tool takes a cURL command and generates equivalent JavaScript (fetch), Python (requests), Go, or PHP code. Together, they let you translate between HTTP representations in both directions — useful when working with API documentation, legacy code, or cross-team collaboration.

Frequently Asked Questions

Why does my fetch() not parse correctly? The most common reason is a variable URL (fetch(myUrl, ...)). The parser needs a literal string. Also check that the options object is inline, not stored in a separate variable.

Does the tool send my data anywhere? No. All parsing and conversion runs entirely in your browser using JavaScript. Your URLs, tokens, and request bodies never leave your device.

How do I run the cURL command on Windows? Windows 10 and 11 include curl.exe. Open Command Prompt or PowerShell and paste the command. Note that single quotes may need to be replaced with double quotes on older Windows versions — use PowerShell 7+ for best compatibility.

Can I convert async/await fetch() calls? Yes. The await keyword is ignored during parsing. The converter only looks at the fetch() call itself, not the surrounding async function structure.

What if my fetch() uses AbortController or signal? The signal option is ignored since cURL does not have an equivalent concept. The rest of the options (URL, method, headers, body) are still converted correctly.

Related Tools

More DevOps & Networking Tools