SyntaxStudy
Sign Up
JavaScript POST Requests with Fetch
JavaScript Beginner 3 min read

POST Requests with Fetch

POST with Fetch

Pass an options object with method, headers, and body to send data. Always set Content-Type when sending JSON.

Example
const res = await fetch("/api/users", {
  method: "POST",
  headers: { "Content-Type": "application/json", "Accept": "application/json" },
  body: JSON.stringify({ name: "Alice", email: "alice@example.com" }),
});
const created = await res.json();
console.log(created.id);
Pro Tip

JSON.stringify() the body and set Content-Type: application/json — fetch does not do this automatically.