cURL to fetch
Convert a curl command into a JavaScript fetch() call, with headers, query string, body and basic auth carried over, live in your browser.
Generated files
Generated code appears here.
Diagnostics appear here after you paste your input.
Processed locally in your browser. Your data never leaves your device.
About this curl to fetch converter
Paste a curl command and get a JavaScript fetch() call: method, URL, query string, headers, body and basic auth carried over exactly, ready to paste into browser or Node code. This page is the fetch output of the cURL to Code studio; Axios, Laravel Http and Guzzle are one click away and use the same parsing.
A worked example
This curl command:
curl 'https://api.example.com/v1/users?active=true' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-H 'authorization: Bearer abc.def.ghi' \
--data-raw '{"name":"Ada Lovelace","role":"admin"}'becomes:
const response = await fetch("https://api.example.com/v1/users?active=true", {
method: "POST",
headers: {
accept: "application/json",
"content-type": "application/json",
authorization: "Bearer abc.def.ghi",
},
body: "{\"name\":\"Ada Lovelace\",\"role\":\"admin\"}",
})The query string stays on the URL, matching how curl itself sent the request. Turn off the Await option to get a plain fetch(...).then(...) promise instead, for code outside an async function.
How to use it
- Paste a curl command, drop a file, or load an example.
- Choose whether the call should be awaited.
- Copy or download the generated file.
Frequently asked questions
- Why is the body a string instead of an object?
- fetch's body option always takes a string (or FormData, Blob, etc.), never a plain object, so a JSON body is emitted as its exact source text rather than re-serialized JSON.stringify(...) output — the request sent is byte-for-byte what curl would have sent.
- What about a file upload?
- A multipart field written as name=@file.png becomes a FormData with a comment marking that field as a file: the file was never read (the browser cannot read curl's local disk), so you attach the real File or Blob yourself where the comment says.
- Does it add error handling?
- No. fetch() only rejects on a network failure, not on a 4xx/5xx response, so the generated code is left as the plain await call for you to wrap however your project already handles errors (checking response.ok, a try/catch, etc.).