Embed this tool on your site
About this tool
Every browser DevTools panel has a 'Copy as cURL' option, but your codebase is JavaScript and what you need is a fetch() call. This tool converts simple cURL commands into a fetch() snippet as you type. It reads the URL that directly follows curl, the method from -X, every -H header written in quotes, and a body passed with --data or --data-raw. The output always sets method (GET when -X is absent, even when a body is present) and passes the body as a plain string. The parser is basic: it does not understand -d, -u, -F, --json or --data-urlencode; a body that contains quote characters, such as JSON wrapped in single quotes, is cut off at the first quote; and if a flag comes before the URL, the flag is taken as the URL. Check the output against the original command before using it. The conversion runs entirely in your browser, so Bearer tokens and session cookies in the cURL string never touch a server.
Why use it
Headers Translated: Every quoted -H flag becomes a key-value entry in the fetch headers object, keeping header names and values as written, including Authorization, Content-Type and custom API keys.
Method Mapping: The -X value (POST, PUT, PATCH, DELETE and others) becomes the upper-cased method property.
Form and Text Bodies: A --data or --data-raw value without quote characters, such as name=Alice&role=admin, becomes the body string unchanged.
Live Output: The fetch() snippet regenerates on every keystroke, so you can adjust the cURL command and watch the result change.
Local Conversion: The entire conversion happens inside your browser using JavaScript string parsing. Bearer tokens, session cookies, and API keys embedded in the cURL command are never transmitted to any server.
How to use
- Write or paste a cURL command with the URL directly after curl, for example curl https://api.example.com/users -X POST.
- Put -H headers in quotes and pass any body with --data or --data-raw.
- Watch the equivalent fetch() call appear in the fetch() output box as you type.
- Check the method, headers object and body against the original command, especially for JSON bodies and DevTools copies.
- Select and copy the snippet from the output box and paste it into your async function or file.
- Add .then() / await response.json() and error handling before shipping
When it helps
- You have a short cURL example with a URL, -X, -H and a simple --data body and want it as fetch code
- You are migrating a shell script that uses simple cURL calls to a Node.js service
- You received a cURL example from an API vendor's documentation and want a starting point for a fetch call
- You want a headers object generated from a list of -H flags without retyping each one
- You are learning how cURL options map to fetch() options
Examples
Inputcurl https://api.example.com/me -H "Authorization: Bearer abc123"
Expected resultfetch("https://api.example.com/me", {
method: "GET",
headers: {
"Authorization": "Bearer abc123"
}
});
Inputcurl https://api.example.com/users -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "name=Alice&role=admin"
Expected resultfetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "name=Alice&role=admin"
});
Inputcurl https://api.example.com/users/42 -X DELETE
Expected resultfetch("https://api.example.com/users/42", {
method: "DELETE"
});
Tips
- After conversion, add credentials: 'include' if the original cURL used session cookies that need to travel with the browser request.
- DevTools-copied cURL commands often include browser-specific headers like sec-ch-ua and sec-fetch-site — trim those before using in a non-browser context.
- Use AbortController with a setTimeout to mirror cURL's --max-time flag and prevent hung requests in production code.
- For Node.js 18+ you can use the built-in fetch directly; for older versions, replace it with the undici or node-fetch package.
- For JSON bodies, set body: JSON.stringify({...}) in the output yourself; the converter does not parse JSON and stops at the first quote inside the data.
Frequently Asked Questions
Which cURL options are supported?⌄
The URL right after curl, -X for the method, -H for headers (in single or double quotes), and --data or --data-raw for the body. Other options, including -d, -u, -F, --json, --data-urlencode, -b and --compressed, are ignored.
What is the difference between fetch and axios?⌄
fetch is a built-in browser and Node.js API that returns a Promise resolving to a Response object. axios is a third-party library that provides a higher-level API with automatic JSON parsing, request interceptors, and broader browser compatibility. The converted fetch code works natively without any dependencies.
Why does my fetch fail with CORS when cURL works?⌄
cURL sends a direct HTTP request with no origin header, bypassing CORS entirely. Browsers enforce CORS and will block responses unless the server includes the correct Access-Control-Allow-Origin header. This is a server-side configuration issue, not a problem with the converted fetch code.
How do I send cookies with fetch?⌄
Add credentials: 'include' to the fetch options object. This tells the browser to attach cookies for the target origin, mirroring what cURL does when you use the -b or --cookie flag.
Why is my JSON body cut off to just {?⌄
The body parser stops at the first quote character of either kind. A body like '{"name":"Alice"}' stops at the first double quote, leaving only {. Replace the body in the output with JSON.stringify({...}) yourself.
Why is the URL in the output -X?⌄
The tool takes the first word after curl as the URL. Put the URL straight after curl, as in curl https://api.example.com/users -X POST, with the flags after it.
Does it convert -X PATCH and DELETE correctly?⌄
Yes. Whatever letters follow -X are upper-cased and used as the method property, including PATCH, DELETE, HEAD and OPTIONS.
Why does the output say method GET when my command sends data?⌄
cURL switches to POST automatically when you pass --data, but this tool sets the method only from -X. Add -X POST to the command, or change the method in the output.
Glossary
- cURL
- A command-line tool for transferring data with URLs. It supports dozens of protocols and is the de facto standard for testing HTTP APIs from a terminal.
- fetch
- A browser and Node.js built-in API for making HTTP requests. It returns a Promise and is the modern replacement for XMLHttpRequest in web applications.
- HTTP method
- The verb that describes the intended action of an HTTP request: GET retrieves data, POST submits data, PUT replaces a resource, PATCH updates it partially, and DELETE removes it.
- Header
- A key-value pair sent with an HTTP request or response to convey metadata such as content type, authorization credentials, caching directives, or custom application context.
- Request body
- The optional data payload sent with POST, PUT, or PATCH requests. Common formats include JSON (application/json) and form-encoded data (application/x-www-form-urlencoded).
- CORS
- Cross-Origin Resource Sharing is a browser security mechanism that restricts web pages from making requests to a different origin unless the server explicitly allows it via Access-Control-Allow-Origin headers.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.
Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.
✳
✳
✓ Free to use✓ No sign-up✓ 500+ possibilities