JustConvertAll-in-One Convert

cURL to Fetch Converter

Convert cURL commands to JavaScript fetch() code instantly in your browser. Supports headers, methods, body, and auth. No data leaves your device.

Related Tools

Advertisement

cURL is the universal command-line HTTP client, used in API documentation, terminal testing, and server-side scripting. When developers copy cURL commands from browser DevTools ('Copy as cURL'), API docs, or Stack Overflow and need to integrate them into a JavaScript or TypeScript frontend or Node.js backend, they must translate the cURL syntax into the equivalent fetch() API call — a repetitive and error-prone manual process.

The cURL command structure and the fetch() API differ significantly in how they express the same request. cURL uses flags: -X for method, -H for headers, -d for body, -u for Basic Auth. The fetch() API uses a URL argument and an options object with method, headers, and body properties. Converting between them requires parsing each flag's argument and mapping it to the correct fetch options property.

This tool parses cURL commands in the browser using pure JavaScript and generates the equivalent fetch() call with all options correctly mapped. It handles -X, -H, -d/--data, --data-urlencode, -u (Basic Auth), --compressed, and -L flags. The output is formatted JavaScript ready to paste into a browser console, a React component, a Node.js script, or a TypeScript file. For type-safe projects, the generated fetch call works without modification in TypeScript.

Common Use Cases

Porting API documentation examples to JavaScript

Most REST API documentation (Stripe, Twilio, GitHub API, OpenAI) provides code examples as cURL commands because cURL is language-agnostic and universally understood. JavaScript developers implementing these APIs in a React application or Node.js backend start by copying the cURL example and converting it to fetch() or axios. The converter eliminates the manual mapping work and reduces the chance of misplacing headers or body parameters.

Converting browser DevTools network requests to code

Chrome, Firefox, and Safari DevTools allow right-clicking any network request and selecting 'Copy as cURL'. This feature is invaluable for capturing authenticated API requests with all cookies and headers. Converting the copied cURL command to fetch() produces JavaScript that replicates the exact request, including session cookies and auth headers — useful for debugging, testing, and automating browser-observed API calls.

Migrating shell scripts to JavaScript services

Backend engineers migrating shell scripts or Python services to Node.js microservices encounter cURL commands that need to be rewritten as fetch() calls. When a script contains dozens of API calls expressed as cURL, converting them one by one to fetch() is mechanical work. The converter handles each cURL command individually and produces clean, consistent fetch() code that matches Node.js 18+ built-in fetch conventions.

How to Use

  1. Copy a cURL command from your terminal, browser DevTools, or API documentation.
  2. Paste it into the input panel (with or without the curl prefix).
  3. The equivalent JavaScript fetch() code appears instantly on the right.
  4. Click Copy Output to copy it to your clipboard.
  5. Paste directly into your JavaScript or TypeScript project.

Supported cURL Flags

Example

curl -X POST https://api.example.com/data \
  -H 'Content-Type: application/json' \
  -d '{"key":"value"}'