cURL to JavaScript fetch — Turn a curl Command into fetch() Code
Convert raw DevTools curl commands cleanly into async JS fetch() snippets.
| Method | POST |
|---|---|
| URL | https://example.com/api/v1/tiket?status=buka |
| Headers | Accept: application/json |
| X-Request-Id: 7f3c-uji | |
| Authorization: Basic YWRtaW46cmFoYXNpYQ== | |
| Content-Type: application/x-www-form-urlencoded | |
| Body | judul=Wi-Fi+lantai+2+mati&catatan=AP+%22lobby%22+%26+ruang+rapat |
- The command is read the way a shell reads it: single and double quotes, backslashes, continuation lines and $'…'. Combined options such as -sSL or -XPOST, repeated -d (joined with &), -G, --json, -F, -u, -b, -A and -e follow curl's own rules.
- Headers curl adds on its own are written too, such as Content-Type application/x-www-form-urlencoded for -d and Authorization Basic for -u, so the server receives the same request. Testing sends real curl and the generated code to a test server and compares the requests it receives.
When to use the curl Command to JavaScript fetch() & axios Converter
From Copy as cURL to app code
Copy a request from the DevTools Network tab with Copy as cURL, paste it here and get fetch() code that sends the same request from a browser or Node.js 18 and later.
Read the way a shell reads it
Single and double quotes, backslashes, continuation lines and $'…' are read as bash reads them, then curl's options are translated: repeated -d is joined with &, --data-urlencode is encoded, -G moves the data into the URL and -u becomes an Authorization header.
curl's own headers are included
curl adds a Content-Type for -d and --json without you writing it. That header goes into the code too, so the server gets the same request instead of a sudden text/plain from fetch.
Tested against real curl
Testing sends the real curl command and the generated fetch code to the same test server and compares the method, URL, headers and body it receives. Both must match exactly, quotes, & and non-ASCII text included.
Frequently asked questions
Are redirects followed?
As in curl: without -L the code uses redirect: "manual"; with -L fetch follows redirects as usual.
What about -k?
fetch cannot turn off certificate checks. Fix the server's certificate or use Node.js with a custom agent.
What about headers with non-ASCII characters?
curl sends them as UTF-8 bytes. The code writes the same bytes so the server receives an identical value.
Is my command run?
No. The command is only read and converted in your browser, without sending any request.
Similar tools
- HTML Beautifier & Indentation PrettifierRe-indent messy single-line HTML markup into readable nested element trees.
- HTML Whitespace & Comment MinifierCompress HTML documents by removing redundant whitespace & HTML comments.
- HTML to Clean GitHub Markdown ConverterConvert headings, links, bold/code tags & lists from HTML into clean Markdown.
- Markdown Live Previewer & HTML GeneratorWrite Markdown and simultaneously render clean semantic HTML & live preview.