Axios request code with headers, data, auth and timeout
fetch() Code Generator
Get ready-to-paste fetch code for a request, including error handling.
Loading tool…
How to use fetch() code generator
Fill in the method, URL, headers, body and auth, or load a curl command.
Copy the fetch code, which checks response.ok and parses the body.
Switch to another language from the same request if you need it.
What this tool does
- Writes JSON bodies as JSON.stringify of a readable object instead of an escaped string.
- Uses URLSearchParams for form bodies and FormData for multipart uploads.
- Adds AbortSignal.timeout when you set a timeout in an imported curl command.
- Works in browsers and in Node.js 18 and later, which ship fetch.
How the result is verified
Every snippet is built from the same parsed request as the cURL output, and generated code is valid JavaScript (checked with node --check during development).
Frequently asked questions
Does fetch throw on a 404?
No. fetch only rejects on network failures. The generated code checks response.ok and throws for any status outside 200 to 299.
Will this code work in Node.js?
Yes on Node.js 18 and later, where fetch is built in. Top-level await needs an ES module (.mjs or "type": "module").
Is my data uploaded to a server?
No. Everything you drop, paste or type is processed by code running in this browser tab. You can check it yourself: open your browser's developer tools, watch the Network panel, and use the tool. No request carries your data.
Related tools
Turn a curl command into fetch, Axios, Python or HTTPie, and back
Build a correctly quoted curl command from a request form
Send GET, POST, PUT, PATCH and DELETE requests from your browser