Overview
Convert curl commands to JavaScript fetch()
curl is the universal way to describe an HTTP request on the command line, and you see it everywhere: API documentation, the “copy as curl” option in browser devtools, Postman exports, and Stack Overflow answers. But when you sit down to write the same request in a web app or a Node.js script, you need it as a fetch() call instead.
ToolHub curl to fetch converter parses a curl command and rewrites it as clean, ready-to-paste JavaScript. It reads the URL, the request method, every -H header, and the request body, then assembles a fetch() call with a tidy options object. Everything happens in your browser as you type.
Step-by-step
How to convert curl to fetch
- 1
Paste your curl command
Drop the full command into the input panel. Multi-line commands with backslash line continuations work exactly as they are copied from a terminal or API doc. - 2
Read the generated fetch() code
The output updates instantly with the URL, an options object holding the method and headers, and a body when the command sends one. - 3
Copy and adapt
Click copy, paste it into your project, and swap in real values. The code uses async await, so wrap it in an async function if you are not already inside one.
Background
How the parser reads a curl command
A curl command is just a list of shell arguments. The tool tokenizes that list the way a shell would: it respects single quotes, double quotes, and the backslash-newline continuations that break a long command across several lines. From the tokens it picks out the pieces that map onto a fetch request.
How the method is chosen
If the command has an explicit -X or --request flag, that wins. Otherwise the tool follows the same rule curl does: if there is a request body it defaults to POST, and if there is no body it defaults to GET.
How headers and the body are handled
Each -H "Name: value" becomes one entry in the headers object, split on the first colon so values containing colons survive. Body flags including -d, --data, --data-raw, and --data-binary are collected into the request body, and a JSON body is pretty-printed inside JSON.stringify() so it stays readable. Flags the tool does not recognize are skipped instead of breaking the output.
Use cases
When this tool is handy
Porting API docs to your app
Most REST APIs document their endpoints with curl. Convert those examples to fetch() to call them from the browser or Node.
Copy as curl from devtools
Grab a request from the Network tab as curl, then turn it back into fetch() to reproduce it in code.
Onboarding to a new codebase
Translate the curl snippets in a README into the fetch-based pattern your front end already uses.
Writing integration tests
Start from a working curl call and convert it into a fetch() request your test runner can execute and assert on.
Teaching HTTP
Show students the same request expressed two ways, on the command line and in JavaScript, side by side.
Quick prototyping
Sketch an API call in curl first, then drop the generated fetch() into a sandbox to iterate.
Tips and best practices
- Wrap the generated code in an async function, since it uses await on fetch and on response.json().
- If the API returns plain text or binary instead of JSON, switch response.json() to response.text() or response.blob().
- For requests with credentials, you may need to add credentials: "include" to the options object yourself.
- Remove any real tokens before sharing the converted code. A bearer token in a header is a secret.
- Form-encoded bodies are passed through as a string. Set the matching Content-Type header if curl relied on a default.
Common questions
Does it handle multi-line curl commands?
Yes. Backslash followed by a newline is a line continuation, which is how terminals and API docs split a long curl command. The tool joins those lines before parsing, so you can paste the command exactly as you copied it.
What about single quotes versus double quotes?
Both are supported. Shells treat single-quoted text as literal and allow escapes inside double quotes, and the tokenizer follows the same rules so a JSON body wrapped in either kind of quote is read correctly.
Will it run in Node.js too?
The generated code is standard fetch(), which is built into modern browsers and into Node.js version 18 and newer. On older Node you would add a fetch polyfill such as node-fetch.
What happens to flags it does not understand?
They are ignored gracefully. The converter focuses on the URL, method, headers, and body, and skips options like -v or --compressed that do not change the equivalent fetch call.
100% private