Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Headers can be assigned to a fetch request using the Headers constructor and the fetch API:

const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');

fetch('https://example.com', {
  method: 'POST',
  headers: myHeaders,
  body: JSON.stringify({ key: 'value' })
})
.then(response => {
  // handle response
})
.catch(error => {
  // handle error
});