cURL to Fetch Converter
Convert cURL commands into JavaScript Fetch API code. Paste a command from browser DevTools or API documentation, review compatibility warnings, and copy the result. Everything is processed locally.
Your text never leaves your browser.
The command is parsed as text. It is never run.
No code yet
Request summary and compatibility
- Status
- —
- Method
- —
- Host
- —
- Headers
- —
- Body
- —
Paste a curl command or load the sample, then press Convert to Fetch.
Browser fetch() is not curl: CORS, browser-managed cookies and headers, redirects, TLS and proxies all behave differently. Nothing is sent when you convert.
How to convert cURL to JavaScript fetch()
- Paste one curl command into the cURL command box, or load the sample.
- Press Convert to Fetch. The command is parsed as a supported literal subset of POSIX shell syntax.
- Read the request summary and every warning, especially omitted headers and credentials.
- Copy the JavaScript and adapt it, for example by awaiting the response and reading its body.
The converter reads single quotes, double quotes, backslash escapes and backslash line continuations, then maps the supported options to a fetch() call with method, headers and body. Shell features such as variables, $( … ), pipes and ; and Bash $'…' strings are rejected instead of being guessed, because they would change what the shell actually runs.
Converting browser DevTools “Copy as cURL”
In Chrome or Edge, open the Network panel, right-click a request and choose Copy > Copy as cURL (bash). In Firefox choose Copy Value > Copy as cURL. These commands often include Cookie, Sec-Fetch and Sec-CH-UA headers that the browser adds automatically. They are left out of the fetch() code and listed in a warning, because a page cannot set them. The Windows CMD and PowerShell variants are not supported.
Supported cURL options
| Option | Converted as |
|---|---|
| -X, --request | GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS |
| --url, positional URL | Exactly one absolute http:// or https:// URL |
| -H, --header | Request headers; repeated, case-insensitive duplicates must agree |
| -d, --data, --data-raw | Literal body, sent as application/x-www-form-urlencoded unless you set Content-Type |
| --json | Literal JSON body with JSON Content-Type and Accept headers |
| -u, --user | ASCII user:password, encoded as a Basic Authorization header |
| -I, --head | HEAD request |
| -L, --compressed, -s, -S, -g | Recognized; explained in notes, no code needed |
| -b, -A, -e | Recognized but omitted with a warning (cookies, User-Agent, Referer) |
Any other option produces an error that names it. That includes -F multipart forms, --data-binary, --data-urlencode, -G, -k, proxy and TLS settings, and every option that reads a file, such as -d @file.
What browser fetch() cannot reproduce
- CORS. curl reads any response. A browser only exposes a cross-origin response when the server allows your origin, and headers such as Authorization trigger a preflight request first.
- Forbidden headers. Cookie, Host, Origin, Referer, Content-Length, Accept-Encoding, Connection and all Sec- and Proxy- headers are controlled by the browser.
- Cookies and credentials. Browsers attach their own cookies for the target site. Cross-origin cookies also need
credentials: "include"and server permission, which the converter never adds for you. - Redirects. fetch() follows redirects by default, while curl only does with -L, and browsers may rewrite the method or drop credentials along the way.
- GET and HEAD bodies. curl can send them; fetch() throws an error, so such commands are rejected.
- Network settings. TLS verification, client certificates, proxies, timeouts and the HTTP version are all chosen by the browser.
Worked example: GET request
Without a body or -X, curl sends GET. The URL is copied exactly, including its query string, and only the headers you wrote are emitted.
curl 'https://api.example.com/items?limit=10' \ -H 'Accept: application/json'
fetch("https://api.example.com/items?limit=10", {
method: "GET",
headers: {
"Accept": "application/json"
}
});Worked example: JSON POST request
The body stays a string with the exact characters you sent. It is not parsed and re-serialized with JSON.stringify(), so whitespace, key order and large numbers are unchanged. Only one body option is supported. With --json instead of -H and --data-raw, the JSON Content-Type and Accept headers are added for you, as curl does.
curl -X POST 'https://api.example.com/items' \
-H 'Content-Type: application/json' \
--data-raw '{"name":"Ada"}'fetch("https://api.example.com/items", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: "{\"name\":\"Ada\"}"
});Security and privacy
Copied commands often contain bearer tokens, API keys and session cookies. This converter runs entirely in your browser: the command is never executed, no request is sent to the target URL, the generated code is never run, and nothing is uploaded, logged, stored, placed in the page URL or sent to analytics. The generated code keeps any Authorization header or -u credentials in plain text, so review it before sharing it, committing it or shipping it in client-side code. To inspect a token first, use the JWT Decoder.
Related developer tools
Frequently asked questions
How do I convert a cURL command to JavaScript fetch()?
Paste the curl command into the converter and press Convert to Fetch. The URL, method, headers and request body are read from the command and written as a fetch(url, { method, headers, body }) call that you can copy into your code. Options that fetch() cannot reproduce are listed as warnings or errors instead of being dropped silently.
Can I convert a command copied from Chrome DevTools?
Use Copy > Copy as cURL (bash) in Chrome or Copy Value > Copy as cURL in Firefox. Commands using POSIX single or double quotes and backslash continuations are supported. Bash ANSI-C strings ($'…'), Windows CMD and PowerShell syntax are rejected; replace Bash escape strings with POSIX-quoted literal text.
Does this converter support POST, headers and JSON bodies?
Yes. -X and --request set the method, -H adds headers, and -d, --data, --data-raw and --json add a body. A body without -X becomes a POST, as in curl. The body is kept as the exact text you supplied, so JSON formatting and large numbers are not changed. File uploads with -F, --data-binary and @file arguments are not supported.
Why are some cURL headers missing from Fetch?
Browsers forbid scripts from setting certain headers, including Cookie, Host, Origin, Referer, Content-Length, Connection, Accept-Encoding and every Sec- and Proxy- header. The browser sets them itself, so the converter leaves them out and names each one in a warning. Cookies are sent by the browser for the target site according to its own rules.
Will my generated Fetch request work despite CORS?
Not necessarily. curl ignores CORS, but a browser only lets a page read a cross-origin response if the server allows that origin. Custom headers such as Authorization or a JSON Content-Type also trigger a preflight request the server must accept. Same-origin requests and server-side JavaScript runtimes such as Node.js are not limited by CORS.
Are my API tokens or cURL commands uploaded anywhere?
No. Conversion runs entirely in your browser. The command is never executed, the target URL is never contacted and nothing you paste is uploaded, stored or sent to analytics. The generated code does contain any tokens or passwords from your command, so review it before sharing or committing it.