How to use the JavaScript Fetch API

const requestInit = { 
   method: 'GET', headers: {'Content-Type': 'application/json'}, mode: 'cors', cache: 'default'
};
let theRequest = new Request("TheURL", requestInit);
fetch(theRequest)
     .then( (res) => {return res.json(); })
     .then( (data) => { console.log(data); }); 

2 thoughts on “How to use the JavaScript Fetch API

Leave a Reply

Your email address will not be published.