ToolHarbor

cURL to Fetch Converter

Convert curl commands to JavaScript fetch() code. Parses headers, body, method, and auth automatically.

Features

  • Convert curl commands to modern JavaScript fetch() code
  • Parses headers (-H), method (-X), data (-d), and basic auth (-u)
  • Handles multiline curl commands with line continuations
  • Auto-detects JSON bodies and wraps them in JSON.stringify()
  • Works entirely offline — your commands never leave your browser
  • Copy the generated fetch code with one click

How to Use

  1. 1Paste your curl command into the input field
  2. 2Click "Convert" to generate JavaScript fetch code
  3. 3View the generated code on the right panel
  4. 4Click "Copy" to copy the fetch code to your clipboard

Examples

Simple GET request

Input

curl https://api.example.com/users

Output

const response = await fetch("https://api.example.com/users");
const data = await response.json();
POST with JSON body

Input

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"John","email":"john@example.com"}'

Output

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

const data = await response.json();

Why Convert cURL to Fetch?

cURL is the universal command-line tool for making HTTP requests. It is available on virtually every operating system and is the default way API documentation shows example requests. But when you need to integrate those API calls into a JavaScript application, you need to translate the curl syntax into fetch() code — which is where this tool saves you time.

The JavaScript Fetch API is the modern standard for making HTTP requests in browsers and Node.js. It uses Promises, supports streaming, and integrates naturally with async/await. Converting from curl to fetch manually is tedious because you need to restructure headers from -H flags into an object, parse the -d body, map the -X method, and handle authentication differently.

This tool parses the curl command structure automatically: it extracts the URL, HTTP method (-X), headers (-H), request body (-d, --data, --data-raw), and basic authentication (-u). It also handles common curl flags like --compressed, -L (follow redirects), and -k (insecure) — which have no fetch equivalent but should not block the conversion.

JSON bodies are automatically detected and wrapped in JSON.stringify() for clean output. Multiline curl commands with backslash continuations are normalized before parsing. The generated code uses modern async/await syntax with proper formatting that you can paste directly into your project.

Everything runs in your browser. Your curl commands — which may contain API keys, auth tokens, or internal endpoints — are never sent to any server. The parsing happens entirely in client-side JavaScript.

Frequently Asked Questions

Related Tools