curl to fetch converter
Updated Free mock REST & WebSocket APIs
Turn any curl command into a JavaScript fetch() call you can paste into the browser console, a React app or Node.js 18+, where fetch is built in.
POST https://mockfox.dev/api/fake/posts2 headersbody 52 chars
const response = await fetch("https://mockfox.dev/api/fake/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_TOKEN",
},
body: JSON.stringify({
"title": "Hello",
"body": "From curl",
"userId": 1
}),
});
const data = await response.json();🔒 Converted in your browser — your command, tokens and URLs are never sent anywhere.
How to convert a curl command
- Paste the command into the box (multi-line commands with
\continuations are fine) — or copy one from DevTools with Copy as cURL. - Pick the output language. The code updates as you type.
- Copy or download the code, and check any warnings about options that can't be converted.
fetch vs curl: differences to know
- fetch doesn't reject on HTTP errors. A 404 or 500 resolves normally; check
response.okorresponse.status. - Basic auth becomes an
Authorization: Basic …header with the base64-encoded credentials. - Multipart uploads use
FormData; never setContent-Typeyourself, or the boundary will be missing. - In browsers, CORS applies and headers like
CookieandUser-Agentcan't be set. Usecredentials: "include"to send cookies.
Need an endpoint to try your code against? Use the free fake REST API or test any HTTP status code.
Related tools
Frequently asked questions
Is my curl command sent to a server?
No. The converter runs entirely in your browser, so API keys, tokens and URLs in your command never leave your device.
Why does my converted fetch fail with a CORS error?
curl doesn't enforce CORS but browsers do. The API must send Access-Control-Allow-Origin for your origin, or you need to call it from a server (Node.js, a route handler) instead.
Does the output work in Node.js?
Yes. Node.js 18 and later include fetch, FormData and Blob globally, so the code runs as-is in an ES module (top-level await) or inside an async function.
Your business here? Sponsor this tool from $16/week. See placements