cURL ↔ fetch() Converter
Paste a cURL command copied from browser dev tools or an API doc, and get back a ready-to-use JavaScript fetch() call — or go the other direction, converting existing fetch() code into a cURL command you can run from a terminal.
Why this saves more time than it looks like it should
Copying a request as cURL is the default export option in every browser’s Network tab, Postman, and most API documentation examples — but cURL syntax and JavaScript’s fetch() API structure headers, methods, and request bodies completely differently. Manually translating one into the other means carefully re-typing headers as an object, converting -d flags into a body property with the right JSON.stringify() wrapping, and remembering to set method: 'POST' explicitly since fetch() defaults to GET while cURL’s behavior depends on which flags you used. It’s a small, fiddly translation that’s easy to get subtly wrong by hand, especially with several headers involved.
How to use it
- Paste a cURL command — copied directly from a browser’s “Copy as cURL” option, Postman, or documentation — into the input panel.
- Get back a complete, working
fetch()call with headers correctly mapped into theheadersobject, the HTTP method set explicitly, and the request body properly formatted as JSON or form data depending on the original content type. - Switch direction to convert existing
fetch()code back into an equivalent cURL command, useful when you want to test a request from the terminal outside your application code, or share a reproducible request with a teammate or in a bug report. - Toggle between
async/awaitand.then()chain style for the generated fetch code, matching whatever pattern the rest of your codebase uses. - A checkbox lets you include or omit browser-specific headers (like
sec-ch-uaoraccept-encoding) that browsers auto-attach and copy into “Copy as cURL” output but usually aren’t needed or wanted in your actual application code.
Common situations this solves
- Turning a request copied from browser dev tools into working application code, without manually re-typing headers and body formatting by hand.
- Reproducing a bug from a terminal by converting a
fetch()call in your codebase into a cURL command you can run directly and tweak, without needing to spin up the full application. - Documenting an API endpoint for teammates, providing both a cURL example (common in API docs and quick terminal testing) and the equivalent JavaScript usage from a single source.
- Debugging a request that works in one context but not another, by converting between formats to isolate whether the issue is in the request itself or in how it’s being made.
- Learning how a specific API call is structured when you’ve only ever seen it as a cURL example in documentation and need the JavaScript equivalent for your own project.
Frequently asked questions
Does the converted fetch() code handle authentication headers correctly?
Yes — Bearer tokens, Basic Auth, API keys, and cookies passed via cURL’s -H or -u flags are all mapped into the appropriate headers object properties in the generated fetch code, formatted exactly as the Fetch API expects.
What happens to the request body when converting a POST request with JSON data?
The tool detects JSON-formatted data passed via cURL’s -d or --data flag and wraps it correctly as body: JSON.stringify({...}), while also adding the appropriate Content-Type: application/json header if it wasn’t already explicitly set in the original command.
Can this handle multipart form data or file uploads?
Yes, cURL’s -F flag for multipart form submissions converts into the equivalent FormData object construction in the generated JavaScript, since this is different enough from simple JSON bodies that it needs its own handling rather than being treated the same way.
Why does the generated fetch() code sometimes include extra headers I didn’t expect?
This usually happens when the original cURL command was copied directly from a browser’s dev tools “Copy as cURL” feature, which automatically includes a full set of browser-identifying headers alongside the ones your application actually set intentionally. Use the toggle to filter these out if you only want the headers your code explicitly needs.
Does this work for non-JavaScript targets, like converting cURL into Python’s requests library?
No, this tool is scoped specifically to the cURL/fetch() pair, since that’s the most common real-world translation need for web developers — for other language targets, most API documentation tools (like Postman) offer broader code-generation options across multiple languages.