Headers and Body
Headers are extra information about a request or response, like the content type or an auth token. The body is the actual data being sent, usually JSON. GET requests normally have no body; POST, PUT, and PATCH usually do.
const res = await fetch("/api/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_TOKEN",
},
body: JSON.stringify({ title: "Hello", content: "First post" }),
})
// Reading response headers
console.log(res.headers.get("content-type"))