fetch to curl Converter
Paste a JavaScript fetch() call and instantly convert it into an equivalent curl command. The converter reads the URL, method, headers, and request body from your fetch() code, then prints a clean, copyable curl command with correct shell quoting. It runs entirely in your browser, parses the code as text, and never sends the request.
ToolsSoup's fetch to curl converter turns a JavaScript fetch() call into an equivalent curl command in one click. Paste a fetch() snippet from your code, your browser's network tab, or API documentation, and the tool reads the URL, request method, headers, and body and rewrites them as a ready-to-run curl command. It maps the method to -X, every header to a -H flag, and the body to -d, with correct single-quote shell escaping so the command pastes straight into your terminal. The code is parsed as text and never executed, and the request is never sent, so everything stays in your browser.
What does the fetch to curl converter do?
The JavaScript fetch() API and a curl command describe the same HTTP request in two different languages. This converter is the inverse of a curl to fetch tool: it reads a fetch() call and rewrites it as curl. It extracts the URL from the first argument, then reads the options object for the method, the headers, and the body. The HTTP method becomes -X (and is omitted for a plain GET), each header becomes its own -H flag, and the body becomes -d. When the body is written as JSON.stringify of an object literal, the inner JSON is emitted as the curl data, so the command sends the same payload your fetch() call would.
How to convert fetch to curl
Turn a fetch() call into a curl command in a few seconds:
- Paste your full fetch() call into the input box, including the URL string and the options object.
- Click Convert to curl to generate the equivalent command.
- Review the curl command, the -X method, the -H headers, and the -d body in the output panel.
- Copy the command and paste it straight into your terminal.
Which fetch() shapes are supported?
The converter handles the request shapes you write most often. The URL is taken from the first string argument to fetch(). In the options object it reads a method string, a headers value written as an object literal (or as a new Headers({...}) call, or an array of key/value pairs), and a body written either as a string literal or as JSON.stringify of an object. For a JSON.stringify body the inner object is emitted as compact JSON data. Single quotes, double quotes, template literals, and escaped characters in your strings are all decoded correctly before being shell-quoted for curl.
Why use this fetch to curl converter?
- Parses your fetch() call as text and never executes it, so pasted code cannot run.
- Maps the method to -X, headers to -H, and the body to -d in a clean curl command.
- Handles headers as an object literal, a Headers() call, or an array of key/value pairs.
- Emits the inner JSON of a JSON.stringify body as the curl data.
- Escapes values with correct single-quote shell quoting so the command is safe to paste.
- Runs entirely in your browser and never sends the request anywhere.
Frequently asked questions
Does this tool run my fetch() code or send the request?
No. The converter reads your fetch() call as plain text and parses it; it never evaluates the code and never makes the HTTP request. Because nothing is executed or sent from this page, the tool works fully client-side with no cross-origin or network limits.
How does it choose the curl method?
If the options object includes a method, that value is used as -X. A plain GET is left off, since curl uses GET by default, which keeps the command short. Any other method, such as POST, PUT, PATCH, or DELETE, is written explicitly with -X.
How are request bodies handled?
A string body becomes the -d data as-is. A body written as JSON.stringify of an object literal is decoded into compact JSON and emitted as the -d data, so the curl command sends the same payload. Object literals that use unquoted or single-quoted keys are normalized into valid JSON first.
What header formats does it understand?
Headers written as an object literal, such as { \u0022Content-Type\u0022: \u0022application/json\u0022 }, are fully supported, including a new Headers({ ... }) wrapper. An array of [key, value] pairs is also handled. Each header becomes its own -H 'Key: Value' flag in the output.
Why are values wrapped in single quotes?
curl runs in a shell, so values that contain spaces or special characters must be quoted. The converter wraps each header and body value in single quotes and uses the standard '\u005c'' trick to escape any embedded single quote, which is the safest way to pass arbitrary text to curl.