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
Unix Timestamp
Convert Unix timestamps to UTC, local time, and ISO 8601 instantly. Auto-detects seconds vs milliseconds.
Base Converter
Convert numbers between decimal, hex, binary, and octal instantly. Free and runs in your browser.
Hash Generator
Generate SHA-1, SHA-256, SHA-384, and SHA-512 hashes instantly. Runs entirely in your browser using the Web Crypto API.
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
- Copy a cURL command from your terminal, browser DevTools, or API documentation.
- Paste it into the input panel (with or without the
curlprefix). - The equivalent JavaScript
fetch()code appears instantly on the right. - Click Copy Output to copy it to your clipboard.
- Paste directly into your JavaScript or TypeScript project.
Supported cURL Flags
-X METHOD— HTTP method (GET, POST, PUT, DELETE, PATCH)-H 'Header: Value'— Request headers-d 'data'/--data— Request body--data-urlencode— URL-encoded form data-u user:pass— Basic authentication--compressed— Mapped to Accept-Encoding header-L— Follow redirects (noted in output)
Example
curl -X POST https://api.example.com/data \
-H 'Content-Type: application/json' \
-d '{"key":"value"}'