Skip to content
Tools

cURL to JavaScript Fetch

Turn a cURL command into a JavaScript fetch() call.

Local
JavaScript (fetch)

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 -X or inferred from the presence of a body.
  • Headers from -H, plus -A, -e and -b mapped to the right header.
  • JSON, form and raw bodies from -d, --data-raw and --data-urlencode.
  • Multipart fields from -F, written as a FormData object.
  • Basic auth from -u, written as an Authorization header.

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.

Feedback welcome

Found a bug in this tool, or want it to do something it does not? Tell us and we will take a look.