Guide1 min readUpdated August 26, 2026
How to convert cURL and fetch requests
Short answer
A cURL command and a fetch() call describe the same HTTP request pieces: URL, method, headers, and body. Convert them by preserving those pieces, then review browser-only differences such as CORS and automatic response compression.
Map the request parts
- URLUse the absolute request URL from the cURL positional argument or the first fetch() argument.
- MethodCopy -X or the fetch method option. If cURL sends data without -X, treat it as POST.
- HeadersConvert each -H line into a headers object, or each headers object entry into a -H flag.
- BodyMap --data-raw, -d, or fetch body to the request body. Use JSON.stringify only when the body is valid JSON.
Try it: cURL to Fetch ConverterPaste cURL and generate fetch code locally.Open tool
Try it: Fetch to cURL ConverterPaste a common fetch() call and generate a cURL command locally.Open tool
Browser fetch has browser rulesA request that works in cURL can fail in fetch when the target API blocks browser origins with CORS, redirects, credentials, or mixed-content rules.