When using fetch api and set headers I can just use object literals or using a Headers object,
const response = await fetch("https://example.org/post", {
headers: {
"Content-Type": "application/json",
...
},
});
// Or
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const response = await fetch("https://example.org/post", {
headers: myHeaders,
});
As MDN document says,
You can pass an object literal here containing header-name:
header-value properties, Alternatively, you can construct a Headers
object, add headers to that object using Headers.append(), then assign
the Headers object to the headers option
I check Headers document but I can’t find the advantages of using it. So why bother ?