cURL to Fetch Converter
Paste a curl command, including “Copy as cURL” from DevTools, and get working JavaScript fetch code with async/await or .then(), proper body handling and error checks.
Runs in your browser. Nothing you add is uploaded.
What the cURL to Fetch Converter does
API documentation, Stack Overflow answers and your browser's “Copy as cURL” all speak curl, but your front-end code needs fetch. This converter reads the curl command the way curl itself does (clustered flags like -sSL, $'…' strings, several -d parts, the Windows format) and writes idiomatic fetch code: JSON bodies as JSON.stringify of an object, form data as URLSearchParams, uploads as FormData and credentials as headers. It also tells you what cannot carry over to a browser.
How to convert curl to fetch
- Paste the curl command. In Chrome, right-click a request in the Network tab and choose Copy, then Copy as cURL.
- Choose async/await or a .then() chain.
- Decide whether fetch should mimic curl's redirect behaviour and whether to include the response.ok error check.
- Copy the generated code. Read the notes underneath for anything that will behave differently in a browser.
- If the request needs credentials or cookies across sites, add credentials: 'include' and make sure the server allows it with CORS.
The cURL to Fetch Converter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.
When to use it
Turning API docs into front-end code
Most API references show curl. Convert the example and adapt it to your app without translating flags by hand.
Reproducing a network request
Copy a request from DevTools as curl, convert it to fetch and replay it from a script or test.
Moving a shell script to Node.js
Node.js 18 and later run fetch natively, so a curl-based script can become a short JavaScript file without dependencies.
Good to know
- fetch does not reject on HTTP errors such as 404. Check response.ok, as the generated code does.
- Do not set Content-Type by hand for FormData. The browser adds the boundary itself.
- Forbidden headers (Cookie, Host, Referer, User-Agent) are ignored in a browser but work in Node.js.
- Use AbortSignal.timeout(ms) for a timeout, as the generated code does for --max-time.
- Parse JSON with response.json() only when the server sends JSON; otherwise use response.text().
Guides that use this tool
Frequently asked questions
Does the generated code work in Node.js?
Why is my Cookie or User-Agent header ignored in the browser?
Why does fetch behave differently from curl on redirects?
Why does my converted request fail in the browser with a CORS error?
What happens to -u user:pass?
What about --compressed?
Related tools
cURL Command Generator
Build a correct curl command from a form, for any shell.
HTTP Status Code Lookup
Look up any HTTP status code: meaning, causes and how to fix it.
HTTP Header Analyzer
Paste HTTP headers to see what each means and what to fix.
HTTP Header Generator
Generate security, CORS, cache and CSP headers for your server.