Back to Home
Published: June 2026•By Web Util Slyce Team•6 min read
cURL to Fetch — Convert Commands to JavaScript
Learn how cURL maps to JavaScript fetch() with practical examples. Convert automatically with our cURL to Fetch Converter or test APIs with the REST Client.
Basic GET Request
cURL
curl https://api.example.com/users
JavaScript Fetch
const res = await fetch("https://api.example.com/users");
const data = await res.json();POST with JSON Body
cURL
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@example.com"}'JavaScript Fetch
const res = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name: "John",
email: "john@example.com"
})
});
const data = await res.json();Common Options Mapping
| cURL Flag | Description | Fetch Equivalent |
|---|---|---|
| -X / --request | HTTP method | method: 'GET' | 'POST' | 'PUT' | 'DELETE' |
| -H / --header | Request header | headers: { 'Content-Type': 'application/json' } |
| -d / --data | Request body | body: JSON.stringify(data) or body: formData |
| -u / --user | Basic auth (user:pass) | headers: { 'Authorization': 'Basic ' + btoa('user:pass') } |
| -b / --cookie | Cookie string | credentials: 'include' or cookie header |
| -k / --insecure | Skip SSL verification | Not possible in browser fetch (CORS/SSL enforced) |
More Examples
PUT with JSON
cURL:
curl -X PUT https://api.example.com/users/1 -H "Content-Type: application/json" -d '{"name":"Updated"}'Fetch:
await fetch("https://api.example.com/users/1", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: "Updated" }) });DELETE
cURL:
curl -X DELETE https://api.example.com/users/1 -H "Authorization: Bearer token123"Fetch:
await fetch("https://api.example.com/users/1", { method: "DELETE", headers: { "Authorization": "Bearer token123" } });Form data upload
cURL:
curl -F "file=@photo.jpg" https://api.example.com/uploadFetch:
const form = new FormData(); form.append("file", file); await fetch("https://api.example.com/upload", { method: "POST", body: form });