To set the content-type of request header when using Fetch API with JavaScript, we set the headers property.
For instance, we write
const options = {
method: method,
headers: new Headers({ "content-type": "application/json" }),
mode: "no-cors",
};
options.body = JSON.stringify(body);
const res = await fetch(url, options);
to set the headers property to a Headers object with the content-type request header.