curl to fetch Converter
Paste a curl command and instantly convert it into equivalent JavaScript fetch() code. The converter parses the URL, method, headers, request body, and basic auth, then prints clean, copyable fetch() code. It runs entirely in your browser and never sends the request.
ToolsSoup's curl to fetch converter turns a curl command into equivalent JavaScript fetch() code in one click. Paste a command you copied from documentation, your browser network tab, or a teammate, and the tool parses the request method, headers, body, basic auth, and URL into a clean fetch() call you can drop straight into your code. It understands shell quoting, so single-quoted and double-quoted arguments and backslash line continuations are all handled correctly. Everything runs locally in your browser, and the request is never sent.
What does the curl to fetch converter do?
curl commands and the JavaScript fetch() API describe the same HTTP request in two different languages. This converter reads a curl command, the kind you find in API docs or copy from your browser's Copy as cURL menu, and rewrites it as a fetch() call. It maps -X to the method, each -H to a headers entry, -d and its variants to the request body, and -u to a Basic Authorization header. When data is present but no method is given, it defaults to POST, just like curl does; otherwise the method defaults to GET. The output is formatted, copyable fetch() code with a .then() chain ready to use.
How to convert curl to fetch
Convert any curl command in a few seconds:
- Paste your full curl command into the input box, including any -X, -H, -d, or -u flags.
- Click Convert to fetch to generate the equivalent JavaScript.
- Review the fetch() call, the headers object, and the request body in the output panel.
- Copy the code and paste it into your project.
Which curl flags are supported?
The converter handles the flags you reach for most often. -X or --request sets the HTTP method. -H or --header adds request headers. -d, --data, --data-raw, and --data-binary set the body. -u or --user becomes a Basic Authorization header. --url and a bare URL argument both set the request URL. -L or --location and -k or --insecure are recognized and noted in the output, since fetch already follows redirects and browsers cannot skip TLS checks. Output-only flags like -s, -i, and -v are ignored because they have no effect on the JavaScript request.
Why use this curl to fetch converter?
- Parses shell quoting correctly: single quotes, double quotes, escaped characters, and backslash line continuations.
- Maps method, headers, body, and basic auth to a clean fetch() call.
- Defaults to POST when a body is present and no method is set, matching curl's behavior.
- Detects JSON bodies and wraps them with JSON.stringify for readable code.
- Adds a ready-to-use .then() response chain so the snippet works immediately.
- Runs entirely in your browser and never sends the request anywhere.
Frequently asked questions
Does this tool send the HTTP request?
No. It only converts the curl command text into JavaScript fetch() code. Nothing is requested or sent from this page, so the converter works fully client-side with no cross-origin or network limits.
How does it decide the HTTP method?
If the curl command includes -X or --request, that method is used. If not, the method defaults to GET, unless the command sends data with -d or --data, in which case it defaults to POST. This mirrors how curl itself chooses the method.
How are request bodies handled?
Each -d, --data, --data-raw, and --data-binary value becomes the request body, joined with an ampersand when there are several. If a Content-Type header of application/json is present and the body is valid JSON, the body is emitted as JSON.stringify of the parsed object for cleaner, editable code.
What happens with -u for basic auth?
A -u or --user value of the form user:password is converted into an Authorization header using the Basic scheme with a Base64-encoded credential, which is exactly what curl sends. The credentials are encoded locally in your browser and never transmitted by this tool.
Why are -L and -k only shown as comments?
The fetch API already follows redirects by default, so -L or --location needs no extra option. Browsers cannot disable TLS certificate verification, so -k or --insecure has no fetch equivalent. The converter adds a short comment to explain each rather than emitting code that would not work.