fetch headers object code example
Example 1: Add no cores to fetch
const data = { funny: "Absolutely not", educational: "yas" }
fetch('https://example.com/api/', {
method: 'POST',
mode: 'no-cors',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(returnedData => {
}).catch(err => {
})
Example 2: .fetch method
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
Example 3: .fetch method
fetch('http://example.com/data.json')
.then(data => data);
.catch(err => console.log(err));