~/tools/-curl-to-fetch-
HTTP tool - cURL to Fetch

$ Convert cURL to JavaScript fetch

Paste a cURL command and get async/await fetch() code for the browser or Node.js 18+, or switch to axios.

// controls

cURL Input

Paste a cURL command and select the output language.

Tip: copy from DevToolsIn Chrome or Firefox, open DevTools → Network, right-click any request → Copy → Copy as cURL.
vultio · -curl-to-fetch-

Generated code

Ready to copy.

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer my-token-123"
  },
  body: "{\"name\":\"Alice\",\"email\":\"alice@example.com\"}"
});

const data = await response.json();
console.log(data);
§ 01
context

Why use an online cURL to fetch converter

API docs, Postman and the browser DevTools all hand you requests as cURL commands, but your frontend or Node.js code needs fetch(). Translating headers, auth and JSON bodies by hand is where subtle bugs creep in.

This cURL to fetch converter parses the command and outputs async/await fetch() code: -X becomes method, each -H becomes a headers entry, -d becomes body, and --user / --oauth2-bearer become an Authorization header. Switch to axios with one click.

Parsing happens entirely in your browser, so bearer tokens and cookies inside the command never leave your machine.

§ 02
scenarios

cURL to fetch converter use cases

01 →Turn a cURL example from API documentation into frontend code for a React, Vue or Svelte app.
02 →Reproduce a request copied with "Copy as cURL" from DevTools inside a Node.js script or test.
03 →Port shell scripts that call APIs with cURL to a Node.js 18+ service that uses native fetch.
04 →Convert cURL snippets shared in Slack or tickets into code you can paste into a Next.js route handler.
§ 03
examples

cURL to fetch converter examples: input and output

POST JSON

$ input
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alice"}'
↳ output
const response = await fetch("https://api.example.com/users", { method: "POST", headers: { "Content-Type": "application/json" }, body: "{\"name\":\"Alice\"}" }); const data = await response.json(); console.log(data);

Basic auth with --user

$ input
curl https://api.example.com/me --user alice:secret
↳ output
const response = await fetch("https://api.example.com/me", { method: "GET", headers: { "Authorization": "Basic YWxpY2U6c2VjcmV0" } });
§ 04
troubleshooting

Common cURL to fetch converter errors and how to fix them

! TypeError: Failed to fetch / blocked by CORS policy

cause:cURL ignores CORS, browsers do not. The API does not return Access-Control-Allow-Origin for your origin.

fix:Call the API from your backend or a Node.js script, or enable CORS for your origin on the server.

! Cookie header is ignored

cause:Browsers forbid setting the Cookie header from fetch.

fix:Use credentials: "include" so the browser sends its own cookies, or run the code in Node.js.

! response.json() throws "Unexpected token"

cause:The endpoint returned HTML or plain text (often an error page), not JSON.

fix:Check response.ok and response.headers.get("content-type") before calling response.json(), or use response.text().

§ 05
workflow

How developers use the cURL to fetch converter in practice

→ Use JSON.stringify for bodies you build in code

The converter keeps the body exactly as in the cURL command. When you replace it with dynamic data, write body: JSON.stringify(payload) and keep the Content-Type header.

→ Check response.ok — fetch does not throw on 4xx/5xx

Unlike axios, fetch only rejects on network errors. Add if (!response.ok) throw new Error(response.status) after the call.

→ Skip the converter for DevTools requests

In Chrome DevTools, Network → right-click → Copy → Copy as fetch gives fetch code directly. Use the converter for cURL from docs, Postman or teammates.

§ 06
tradeoffs

When not to use the cURL to fetch converter

01 →For requests that rely on client certificates or disabled TLS verification (-k): browsers cannot reproduce them.
02 →When the API ships an official JavaScript SDK — use it for retries, pagination and typed responses.
§ 07
limits

cURL to fetch converter limits and implementation notes

~ Supported flags

-X, -H, -d/--data, --user, --oauth2-bearer, --cookie, --insecure, -L and --max-time. Uncommon flags are ignored.

~ Body is passed as a string

Multipart uploads (-F) are not converted into FormData.

§ 08
read more

Related guides

§ 09
references

Standards & references

§ 10
toolbox

Related developer tools

§ FAQ
questions

Frequently asked questions about the cURL to fetch converter

How do I convert a cURL command to fetch?

Paste the command into the input. -X becomes the method option, each -H becomes an entry in headers, -d / --data becomes body, and --user or --oauth2-bearer become an Authorization header. The result uses async/await.


Does the generated fetch code work in Node.js?

Yes. fetch is built into Node.js 18 and later, so the same code runs in the browser and in Node without installing a package. On older Node versions use the axios output instead.


Why does my fetch request fail with CORS when cURL works?

cURL is not a browser, so it ignores CORS. In the browser the target server must return Access-Control-Allow-Origin for your origin. If it does not, call the API from your backend or from Node.js, where CORS does not apply.


Why are cookies or -k (--insecure) not carried over?

Browsers do not let fetch set the Cookie header manually (use credentials: "include" instead) and do not allow disabling TLS verification. The converter adds a note when a cURL flag has no fetch equivalent.


Can I get axios code instead of fetch?

Yes. Switch the target to JavaScript — axios. The same request is converted to an axios call with method, headers and data.


Is my cURL command sent to a server?

No. Parsing and code generation run entirely in your browser, so tokens and cookies in the command never leave your machine.


How do I handle the fetch response and parse JSON in JavaScript?

Modern fetch() code uses async/await: `const response = await fetch(url, options); const data = await response.json();`. Always verify `response.ok` to handle HTTP error status codes gracefully.