curl to fetch Converter
Paste a curl command and get equivalent JavaScript fetch() code, with method, headers, body and basic auth all converted automatically.
Tool guide
What this tool does
curl to fetch Converter parses a curl command, including its method (-X), headers (-H), request body (-d / --data) and basic auth (-u), and generates equivalent JavaScript using the fetch() API, as either an async/await function or a .then() promise chain.
API documentation and browser dev tools’ "Copy as cURL" feature both hand you a ready-to-run curl command, but turning that command into working JavaScript for a web app or Node script still means manually re-typing the URL, method, headers and body into fetch() syntax, which is easy to get subtly wrong.
This converter parses a pasted curl command directly, recognising the -X/--request method flag, -H/--header entries, -d/--data/--data-raw request bodies and -u/--user basic auth credentials, and generates the equivalent fetch() call, either as a modern async/await function or a .then() promise chain.
How to use curl to fetch Converter
- Paste the full curl command, including any line continuations.
- Choose whether to generate async/await code or a .then() promise chain.
- Read the generated fetch() JavaScript.
- Copy it into your project and adjust the response handling for your actual use case.
Tips for better results
- If a curl command includes -d or --data without an explicit -X, this tool defaults the method to POST, matching curl’s own real behaviour.
- Basic auth (-u user:pass) is converted into an Authorization: Basic header with the credentials Base64-encoded, exactly matching what curl does internally.
- The generated code always assumes a JSON response body via res.json(); adjust that to res.text() or another method if the API you’re calling returns something else.
- Multi-line curl commands copied from a browser’s "Copy as cURL" feature, with backslash line continuations, are handled directly without needing to join them into one line first.
Common use cases
- Converting an API documentation example written as a curl command into working JavaScript for a web app.
- Turning a "Copy as cURL" request copied from browser dev tools into fetch() code to reproduce the request programmatically.
- Quickly prototyping a JavaScript API call from a curl command a colleague or support engineer shared.
- Learning the mapping between curl flags and their fetch() equivalents.
Common mistakes to avoid
- Pasting a curl command with options this tool doesn’t recognise (such as file uploads with -F) and expecting them to be converted; only method, headers, data and basic auth are currently handled.
- Forgetting to adjust the response handling if the API doesn’t actually return JSON; the generated code assumes res.json() by default.
- Leaving a real bearer token or API key from a copied curl command in code that gets committed to version control; always move real secrets into environment variables first.
Frequently asked questions
What curl options are supported?
-X/--request for the HTTP method, -H/--header for headers, -d/--data/--data-raw/--data-binary for the request body, -u/--user for basic auth, and -A/--user-agent for a custom User-Agent header.
Does it handle multi-line curl commands with backslashes?
Yes, line-continuation backslashes used when copying a multi-line curl command (common when copying from browser dev tools) are handled directly.
Why does the method default to POST sometimes?
If -d or --data is present without an explicit -X/--request flag, curl itself defaults to a POST request, and this converter mirrors that exact behaviour.
Is the Authorization header shown as plain text or encoded?
Basic auth credentials are Base64-encoded into the Authorization: Basic header exactly as curl itself would send them, not left as plain readable text.
Feedback & suggestions
Help us improve curl to fetch Converter. We read every message.