Curl to Fetch/Axios Converter

Convert curl commands to JavaScript fetch, Axios, or Node.js code instantly. Supports headers, POST data, auth, and cookies.

Your data never leaves your browser
Converted code will appear here...

How to Use

  1. Paste your curl command into the input area. Multi-line commands with backslashes are supported.
  2. Select your target format: Fetch API, Axios, or Node-fetch.
  3. Click Convert to generate the JavaScript code.
  4. Click Copy to copy the output to your clipboard.

Why Convert Curl to JavaScript?

Curl is the universal language of HTTP requests. API documentation, Stack Overflow answers, and browser DevTools all speak curl. But when you need to make that same request from a JavaScript application, you need to translate it into fetch(), axios, or another HTTP client. Doing this by hand is tedious and error-prone, especially for complex requests with multiple headers, authentication, and JSON bodies.

This converter parses your curl command and generates clean, ready-to-use JavaScript code. It handles the most common curl flags that developers encounter daily: request methods, custom headers, POST data, basic authentication, cookies, redirect following, and SSL options.

The Fetch API: Built-In Browser HTTP

The fetch() API is the modern standard for making HTTP requests in browsers. Introduced to replace XMLHttpRequest, it provides a cleaner Promise-based interface. Every modern browser supports it natively with no dependencies required.

Fetch uses a simple two-argument pattern: the URL and an options object containing the method, headers, and body. Unlike XMLHttpRequest, fetch does not reject on HTTP error statuses (like 404 or 500) — you need to check response.ok manually. The response body is consumed via methods like .json(), .text(), or .blob(), each returning a Promise.

One gotcha: fetch does not send cookies by default for cross-origin requests. You need to set credentials: 'include' in the options. This differs from XMLHttpRequest, which sent cookies by default.

Axios: A Developer-Friendly HTTP Client

Axios is a popular third-party HTTP library used in both browser and Node.js environments. It provides several advantages over raw fetch: automatic JSON serialization and deserialization, request and response interceptors for middleware logic, built-in request cancellation via AbortController, and automatic rejection of non-2xx status codes.

Axios also provides convenience methods like axios.get(), axios.post(), and axios.put() that map directly to HTTP methods. For POST and PUT requests, it accepts the data as the second argument and an optional config object as the third, making the code more readable than raw fetch options.

The trade-off is an additional dependency (~13KB gzipped). For projects already using axios, this converter saves time. For new projects where bundle size matters, the native Fetch API is the lighter choice.

Node-fetch: Fetch for Node.js

Node.js versions before 18 did not include a built-in fetch() implementation. The node-fetch package brought the browser Fetch API to the server, providing a near-identical interface. Even with Node.js 18+ including a native fetch (based on undici), many projects still use node-fetch for its maturity and broader ecosystem support.

The node-fetch output from this tool includes the import statement and handles Node-specific options like custom HTTPS agents for SSL verification control — something not available in browser fetch.

Common Curl Patterns Explained

  • -X POST — Sets the HTTP method. Without -X, curl defaults to GET unless -d is present, which implies POST.
  • -H 'Content-Type: application/json' — Adds a custom header. Multiple -H flags add multiple headers.
  • -d '{"key":"value"}' — Sends a request body. Curl automatically sets the method to POST when -d is used.
  • -u user:pass — Sends Basic Authentication by Base64-encoding the credentials and adding an Authorization header.
  • -b 'session=abc123' — Sends cookies with the request via the Cookie header.
  • -L — Follows HTTP redirects (3xx responses). The Fetch API follows redirects by default; axios does too up to a configurable limit.
  • -k — Skips SSL certificate verification. Useful for development with self-signed certificates but should never be used in production.

Copying Curl from Browser DevTools

One of the most common workflows is copying a request from browser DevTools and converting it to code. In Chrome, open the Network tab, right-click any request, and select "Copy" > "Copy as cURL (bash)". In Firefox, right-click the request and select "Copy as cURL". The copied command includes all headers, cookies, and body data from the actual browser request. Paste it into this tool to get clean JavaScript code instantly.

Note that browser-copied curl commands often include many automatic headers like User-Agent, Accept-Language, and sec-ch-ua. You may want to remove unnecessary headers from the output to keep your code clean.

Related Tools

Format JSON API responses with the JSON Formatter. Encode URL parameters with the URL Encoder. Encode API keys and credentials with the Base64 Encoder. Decode JWT tokens from API responses with the JWT Decoder. Generate request body hashes with the Hash Generator. Validate JSON payloads with the JSON Validator.

Learn More

  • Converting cURL to JavaScript — why developers copy cURL from browser DevTools and how to translate it to fetch, axios, and other HTTP clients.

Frequently Asked Questions

What curl flags does this converter support?
The converter supports the most common curl flags: -X (method), -H (headers), -d/--data/--data-raw (request body), -u (basic auth), -b (cookies), -L (follow redirects), and -k (insecure/skip SSL). Multi-line commands with backslash continuations are also handled.
What is the difference between fetch and axios?
The Fetch API is built into modern browsers and requires no dependencies. Axios is a third-party library that provides a simpler API, automatic JSON parsing, request interceptors, and better error handling. For Node.js, node-fetch brings the browser fetch API to the server.
Is my curl command sent to a server?
No. All parsing and code generation happens entirely in your browser using JavaScript. Your curl commands, API keys, and tokens never leave your machine.
How do I handle authentication in the converted code?
If your curl command includes -u (basic auth), the converter automatically generates the appropriate Authorization header with Base64 encoding. Bearer tokens passed via -H headers are preserved as-is in the output code.
Can I convert curl commands from browser DevTools?
Yes. In Chrome or Firefox DevTools, right-click any network request and select "Copy as cURL." Paste the result directly into this tool to get the equivalent JavaScript code.

Code Examples

Learn how to use this tool programmatically in your favorite language.

AI agent tools available. The CodeTidy MCP Server gives Claude, Cursor, and other AI agents access to 47 developer tools. One command: npx @codetidy/mcp

Drop file to load