Skip to content

Curl to Fetch

Convert a curl command into an equivalent JavaScript fetch call.

Curl to Fetch

Convert Raw Curl commands to JavaScript Fetch API code.

Supports -X, -H, -d / --data / --data-raw / --data-binary, -u, -b, -A, --url and -I. Flags that fetch cannot express are reported as comments in the output.

What Curl to Fetch does

Documentation and browser developer tools both hand you curl commands. Turning one into a fetch call by hand means re-typing headers and re-quoting the body, which is exactly the kind of transcription that introduces mistakes.

This converter parses the command's flags and writes out the corresponding fetch call with its method, headers and body.

  • Convert the request method, headers and request body
  • Handle basic authentication, cookies and a user agent flag
  • Name any flag it cannot convert rather than dropping it silently

How to use Curl to Fetch

  1. 1

    Copy the curl command

    In browser developer tools, right-click a request in the Network tab and choose Copy as cURL.

  2. 2

    Paste it in

    Paste the whole command, including line continuations.

  3. 3

    Review the generated fetch call

    Check the method, headers and body, and read any comment noting a flag that could not be converted.

  4. 4

    Adapt it for your code

    Add error handling and response parsing, which the generated snippet does not include.

Example

A POST request with a JSON body

Input

curl -X POST https://api.example.com/items \
  -H "Content-Type: application/json" \
  -d '{"name":"widget"}'

Output

fetch("https://api.example.com/items", {
  "method": "POST",
  "headers": {
    "Content-Type": "application/json"
  },
  "body": "{\"name\":\"widget\"}"
});

Limits and known behaviour

  • The parser handles common flags. Multipart form uploads, curl configuration files and shell substitutions inside the command are not converted.
  • A copied browser request usually carries cookies and authorisation headers. Review the output before sharing it anywhere.
  • The generated code has no error handling and does not read the response; it is a starting point, not a finished function.
  • Browser fetch cannot set every header curl can. Forbidden headers such as Host and Referer are ignored by the browser at runtime.
  • Requests made from a browser are subject to CORS, so a call that works in curl may still be blocked in the page.

Privacy and data handling

Runs entirely in your browser

  • Your input is processed by JavaScript running in this page. The tool sends no request anywhere, so nothing you paste is transmitted or logged by this site.
  • Copied curl commands routinely contain session cookies and bearer tokens. They are parsed in the page and never sent anywhere, but be careful about where you paste the output.
  • Nothing is saved between visits. Closing or reloading the tab discards whatever is in the fields.

Site-wide data handling, including analytics and advertising, is described in the privacy policy.

Frequently asked questions

Why does my converted request fail in the browser when curl works?

Usually CORS. curl is not bound by the same-origin policy, but a browser request is, and the server must send the appropriate access-control headers for the call to succeed from a page.

Does it support axios or Node's http module?

No, the output is the browser fetch API.