cURL to JavaScript Fetch
Turn a cURL command into a JavaScript fetch() call.
This tool needs JavaScript enabled to run in your browser.
What this tool does
This tool turns a cURL command into a JavaScript fetch call. Paste a command, including one copied straight from your browser devtools with Copy as cURL, and it reads the method, URL, headers, query parameters and body, then writes the matching fetch code with an awaited JSON response.
What it understands
- The method, from
-Xor inferred from the presence of a body. - Headers from
-H, plus-A,-eand-bmapped to the right header. - JSON, form and raw bodies from
-d,--data-rawand--data-urlencode. - Multipart fields from
-F, written as aFormDataobject. - Basic auth from
-u, written as anAuthorizationheader.
Good to know
The snippet uses top-level await, so run it inside an async function or a module. File uploads from -F name=@file are left as a commented line, because the browser needs a real file input rather than a path. Options that do not change the request, such as --compressed or -s, are ignored, and anything the parser skips is noted as a comment.
Common use cases
- Turning a request you captured in devtools into front-end code.
- Reproducing an API call in a quick Node.js script.
- Checking exactly what a copied cURL command sends.
Frequently asked questions
- Where can I run the result?
- In a browser module or a Node.js script. The snippet uses top-level await, so run it inside an async function or an ES module.
- What about file uploads?
- Multipart text fields are written as FormData appends. File fields are left as a commented line, because the browser needs a real file input rather than a path.
Learning resources
Testsmith also runs hands-on courses and a free practice app for the skills behind this tool.