get() { return new Promise((resolve, reject) => { fetch(`${baseAPI}/heroes`) .then(response => response.json()) .then(json => resolve(json)) .catch(err => { reject (err); }); }); }
get() { return fetch(`${baseAPI}/heroes`) .then(response => response.json()); }
function fetchPost(uri, body) { return new Request(uri, { method: 'POST', mode: 'cors', headers: { 'Authorization': 'token 123412341234' }, body: JSON.stringify(body) }) } function fetchStatus(response) { return response.ok ? Promise.resolve(response) : Promise.reject(new Error(response.statusText)); } fetch('https://httpstat.us/500') .then(fetchStatus) .then(function(result) { console.log(result) }) .catch(function(err) { console.log('BAD:', err) });
async get() { const response = await fetch(`${baseAPI}/heroes`); return response.json(); }
async get () { return await (await fetch(`${baseAPI}/heroes`)).json() }