Skip to cURL to Fetch converter

cURL to Fetch Converter

Convert a cURL command into clean, copy-ready JavaScript fetch() code in your browser.

cURL to Fetch converter

Output style
Output target

JavaScript fetch()

const response = await fetch("https://api.example.com/users?page=2");

Converted.

Notes

  • Note: cURL does not enforce CORS. Browser fetch to another origin still needs the server to allow it.

Your cURL command is processed in your browser. The converter does not upload your input to EverydayTools servers.

Be careful when pasting production credentials or session cookies into any third-party page.

Ctrl+Enter converts. Ctrl+Shift+C copies. Escape clears when the cURL field is not focused.

Advertisement

Quick Answer

This tool converts cURL commands into JavaScript Fetch API requests you can copy into browser or frontend code.

What Is a cURL to Fetch Converter?

cURL is the command-line client API docs and DevTools use to show a request: the URL, method, headers, and body in one line. The Fetch API is the JavaScript call browsers and modern Node use for the same request. You convert when a doc shows curl and the code you are writing calls fetch().

Those commands usually come from API documentation, a teammate, or Chrome DevTools → Network → Copy as cURL. This page turns that command into code. It does not send the request.

How to Convert cURL to JavaScript Fetch

  1. Copy the cURL command. Copy it from API docs or from Chrome or Edge DevTools with Copy as cURL.
  2. Paste it into the converter. Put the command in the cURL field. Multiline commands with a trailing backslash are accepted.
  3. Convert. Leave Auto convert on, or press Convert. Ctrl+Enter runs a conversion.
  4. Review warnings. Read notes about CORS, cookies, User-Agent, TLS, and local files before you trust the snippet.
  5. Copy the code. Copy or download the fetch() code. Ctrl+Shift+C copies the output.

How cURL Options Map to fetch()

The table is what this converter emits. A flag with no browser equivalent stays in the warning list.

cURLfetch()
URLFirst argument to fetch(). --url is accepted. A missing scheme becomes https://.
-X / --requestmethod. GET is omitted from the snippet. A body with no method becomes POST. -I / --head becomes HEAD.
-H / --headerheaders. Repeated names use Headers.append. Browser-controlled names are kept in the snippet and called out.
-d / --databody. Several -d values are joined with & unless the body is JSON. --data-raw, --data-ascii, and --data-binary are read the same way.
--jsonJSON.stringify, plus Content-Type: application/json when that header is missing.
--data-urlencodeURLSearchParams. With -G / --get, the pairs move onto the query string and the body is removed.
-F / --formFormData. The multipart boundary is left to the browser, so a pasted Content-Type is not copied. @file becomes a file-input placeholder.
-u / --userAuthorization: Basic, encoded from user:password. An existing Authorization header is kept.
-G / --getAppends urlencoded data to the URL and uses GET unless -X says otherwise.
-L / --locationredirect: "follow". Without -L the snippet does not set redirect. A 301, 302, or 303 can still become GET.
-k / --insecureNo option. Browser Fetch cannot disable TLS certificate validation.
-b / --cookieA Cookie header. Page JavaScript usually cannot set it. Use credentials: "include" only when the server and CORS allow it.

Convert cURL JSON POST Requests

A JSON POST needs the method, Content-Type: application/json, and a body that JSON.parse accepts. The snippet uses JSON.stringify so quotes survive. Check the payload in the JSON Formatter or describe it with the JSON Schema Generator.

JSON POST

A JSON body with a bearer token. The token is the placeholder TOKEN.

cURL

curl -X POST "https://api.example.com/users" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer TOKEN" \
  -d '{"name":"John"}'

fetch()

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer TOKEN"
  },
  body: JSON.stringify({
    name: "John"
  })
});

Convert cURL GET Requests

A GET with a query string stays on the URL. The method is omitted because fetch() already defaults to GET. Split that URL with the URL Parser or the Query String Parser if the query is the part you need to edit.

GET request

A read request with a query string. fetch() uses GET when you omit the method.

cURL

curl "https://api.example.com/users?page=2"

fetch()

const response = await fetch("https://api.example.com/users?page=2");

Convert cURL Requests With Headers

Each -H is one header. Build a longer list in the HTTP Header Generator before you paste. A custom key such as YOUR_KEY is a placeholder. Create a real key with the API Key Generator and keep it on the server.

Custom headers

Accept and a custom API key header. YOUR_KEY is a placeholder.

cURL

curl "https://api.example.com/users" \
  -H "Accept: application/json" \
  -H "X-API-Key: YOUR_KEY"

fetch()

const response = await fetch("https://api.example.com/users", {
  headers: {
    "Accept": "application/json",
    "X-API-Key": "YOUR_KEY"
  }
});

Convert cURL With Bearer Authentication

Authorization: Bearer TOKEN is copied as a header. TOKEN is a placeholder. A production bearer token in frontend code is visible to anyone who loads the page. Inspect a token you already hold with the JWT Decoder, and keep the live secret in a server environment you can review with the .env Parser.

DELETE with bearer auth

A delete call. The authorization value is a placeholder, not a live token.

cURL

curl -X DELETE "https://api.example.com/users/123" \
  -H "Authorization: Bearer TOKEN"

fetch()

const response = await fetch("https://api.example.com/users/123", {
  method: "DELETE",
  headers: {
    "Authorization": "Bearer TOKEN"
  }
});

Convert cURL Form Data

application/x-www-form-urlencoded is name/value pairs in the body, the same shape as an HTML form. -F is multipart. Multipart can carry a file, and the browser sets the boundary, so do not copy a cURL Content-Type that already includes a boundary. Encode a single value with the URL Encoder & Decoder if you are checking one field by hand.

URL-encoded form

Two fields encoded the way an HTML form posts them. The password is the placeholder secret.

cURL

curl -X POST "https://api.example.com/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "email=test@example.com" \
  --data-urlencode "password=secret"

fetch()

const response = await fetch("https://api.example.com/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  body: new URLSearchParams({
    email: "test@example.com",
    password: "secret"
  })
});

Convert Chrome DevTools “Copy as cURL” Requests

Chrome and Edge can turn a captured request into cURL. Open DevTools, choose Network, right-click the request, then Copy → Copy as cURL (bash) or Copy as cURL (cmd). Paste that text here. The converter accepts backslash continuations and Windows caret continuations, including ^& inside a quoted URL.

DevTools also copies headers the browser sets itself, such as User-Agent, Cookie, and Sec-Fetch-*. Those stay visible in the warnings. They are not silently removed, and browser fetch still will not let page JavaScript set them.

Browser Fetch Limitations

  • CORS still applies. Converting the command does not make another origin accept the call.
  • Host, Content-Length, Cookie, Referer, User-Agent, and Sec-* headers are controlled by the browser. Node.js Fetch can send several of them. Switch the target if that is the runtime you are writing for.
  • A Cookie header from cURL does not become a working browser cookie. You may need credentials: "include" and a server that allows it.
  • -k cannot turn off certificate checks in the browser.
  • A pasted path such as @photo.jpg is not a file the page can read. Pick the file with an input.
  • Authorization and basic auth are copied so the snippet is usable. Do not leave production credentials in frontend source. Basic auth is standard Base64, which the Base64 Encoder/Decoder can inspect. It is not encryption.

Common cURL to Fetch Conversion Mistakes

  • Sending JSON with the default -d content type. Without Content-Type: application/json or --json, cURL uses application/x-www-form-urlencoded. If the single body parses as JSON, this converter switches to JSON.stringify and says that it did.
  • Joining several -d flags with & and expecting one JSON object.
  • Copying a multipart Content-Type, boundary included, into fetch(). The browser must set that header.
  • Expecting -k, --proxy, or a client certificate to work in page JavaScript.
  • Putting a session cookie or bearer token from DevTools into a public frontend bundle.
  • Breaking quotes while editing the command by hand. The String Escaper shows the escaped form. Validate a JSON body with the JSON Validator before you convert again.

How This Converter Works

  1. Normalize line endings and join backslash, caret, and backtick continuations.
  2. Tokenize single quotes, double quotes, and escapes so a header or JSON body stays one word.
  3. Parse the URL, method, repeated headers, data, forms, auth, and cookies.
  4. Map those fields to fetch() or Axios options.
  5. Check the result against browser limits for the target you selected.
  6. Generate the snippet. GET omits the method. JSON uses JSON.stringify.
  7. Attach a warning for every flag or header that fetch() cannot honor.

Shell variables such as $TOKEN are not expanded. Unknown flags are named in the warning list instead of being dropped. After the snippet looks right, sketch the response with the API Mock Generator.

Real Examples

GET request

A read request with a query string. fetch() uses GET when you omit the method.

cURL

curl "https://api.example.com/users?page=2"

fetch()

const response = await fetch("https://api.example.com/users?page=2");

JSON POST

A JSON body with a bearer token. The token is the placeholder TOKEN.

cURL

curl -X POST "https://api.example.com/users" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer TOKEN" \
  -d '{"name":"John"}'

fetch()

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer TOKEN"
  },
  body: JSON.stringify({
    name: "John"
  })
});

Custom headers

Accept and a custom API key header. YOUR_KEY is a placeholder.

cURL

curl "https://api.example.com/users" \
  -H "Accept: application/json" \
  -H "X-API-Key: YOUR_KEY"

fetch()

const response = await fetch("https://api.example.com/users", {
  headers: {
    "Accept": "application/json",
    "X-API-Key": "YOUR_KEY"
  }
});

DELETE with bearer auth

A delete call. The authorization value is a placeholder, not a live token.

cURL

curl -X DELETE "https://api.example.com/users/123" \
  -H "Authorization: Bearer TOKEN"

fetch()

const response = await fetch("https://api.example.com/users/123", {
  method: "DELETE",
  headers: {
    "Authorization": "Bearer TOKEN"
  }
});

URL-encoded form

Two fields encoded the way an HTML form posts them. The password is the placeholder secret.

cURL

curl -X POST "https://api.example.com/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "email=test@example.com" \
  --data-urlencode "password=secret"

fetch()

const response = await fetch("https://api.example.com/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  body: new URLSearchParams({
    email: "test@example.com",
    password: "secret"
  })
});

Related Developer Tools

Assemble the URL first with the URL Builder, then paste the cURL command here. More request utilities are on the developer tools page.

Frequently Asked Questions

What is a cURL to Fetch converter?

A cURL to Fetch converter reads a cURL command and writes the matching JavaScript fetch() call: the URL, method, headers, and body.

How do I convert cURL to JavaScript?

Paste the command, press Convert, read any warnings, and copy the fetch() code. Ctrl+Enter converts. Ctrl+Shift+C copies the output.

Can I convert cURL to fetch() online?

Yes. This page runs in the browser. It does not upload the command and it does not require an account.

Can this converter handle JSON request bodies?

Yes. --json, a Content-Type of application/json, or a single -d value that parses as JSON becomes JSON.stringify. Invalid JSON stays a string, and the page says so.

Can it convert cURL headers?

Yes. Each -H or --header becomes a headers entry. Repeated names use Headers.append so a later header does not overwrite an earlier one.

Can it convert Bearer token authentication?

Yes. An Authorization: Bearer header is copied into the headers object. Do not ship a production token in frontend code.

Can it convert cURL form data?

Yes. --data-urlencode and form-urlencoded -d values become URLSearchParams. -F and --form become FormData. A path such as @photo.jpg cannot be read from the paste, so the snippet leaves a file-input placeholder.

Can I convert a Chrome DevTools “Copy as cURL” request?

Yes. In Chrome or Edge, open Network, right-click the request, choose Copy, then Copy as cURL, and paste it here. Windows copies that use caret line breaks are accepted.

Does the converter upload my cURL command?

No. Your cURL command is processed in your browser. The converter does not upload your input to EverydayTools servers.

Why can some cURL flags not be converted to browser Fetch?

fetch() is a browser API. It cannot disable TLS checks, choose a proxy, read a local file path, or set headers the browser controls, such as Cookie, Host, User-Agent, Referer, and Content-Length.

Can cURL to Fetch work with POST and DELETE requests?

Yes. -X and --request set the method. A body without an explicit method becomes POST. -I becomes HEAD.

Does browser fetch behave exactly like cURL?

No. cURL ignores CORS, follows redirects only when you pass -L, and can set Cookie and User-Agent. Browser fetch enforces CORS, follows redirects by default, and blocks those headers.

Can I convert cURL to Axios or Node.js fetch?

Yes. Choose Node.js Fetch or Axios in the output options. Node can send Cookie, Host, and User-Agent. Axios uses data instead of body and needs the axios package.