Back to Home
Published: June 2026By Web Util Slyce Team6 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 FlagDescriptionFetch Equivalent
-X / --requestHTTP methodmethod: 'GET' | 'POST' | 'PUT' | 'DELETE'
-H / --headerRequest headerheaders: { 'Content-Type': 'application/json' }
-d / --dataRequest bodybody: JSON.stringify(data) or body: formData
-u / --userBasic auth (user:pass)headers: { 'Authorization': 'Basic ' + btoa('user:pass') }
-b / --cookieCookie stringcredentials: 'include' or cookie header
-k / --insecureSkip SSL verificationNot 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/upload

Fetch:

const form = new FormData(); form.append("file", file); await fetch("https://api.example.com/upload", { method: "POST", body: form });