Skip to content
Categories
curl to fetch Converter
Convert a curl command into JavaScript fetch() code.
Overview
- Converts a curl command — such as one copied from API documentation or a browser's developer tools ("Copy as cURL") — into JavaScript fetch() code.
- Supports the method (-X), headers (-H), request body (-d), and Basic authentication (-u).
- The conversion happens entirely in your browser.
Usage
- Paste the curl command into the input field.
- Click the "Convert" button.
- The corresponding fetch() JavaScript code is displayed.
Example
Input
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alice"}'Output
fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: "{\"name\":\"Alice\"}",
});Use Cases
- Quickly porting a curl example from API documentation into frontend code
- Reproducing a request copied from a browser's developer tools as JavaScript
- Reviewing the request details (headers, body) represented by a curl command in a structured form
FAQ
How is a curl command without -X converted?
If a request body is specified with -d, it is converted as POST; otherwise as GET — the same default behavior as curl itself.
What happens to options other than the request itself (-s, -L, --compressed, etc.)?
Options that don't affect the fetch() call are ignored and do not appear in the output.
Are there curl options that aren't supported?
Yes. Advanced options such as -F (multipart form data) or --cacert are not supported. This tool is intended for converting basic HTTP requests.
Notes
- The generated code performs only a basic conversion. Add error handling and response processing as appropriate for your environment.
- When working with a curl command that contains sensitive information like a password, be careful with how you handle the generated code as well.
Related Tools
Convert a docker run command into a docker-compose.yml service definition.
Format HTML to make it easier to read.