Requests
fetch('https://www.example.com')
.then(response => {
console.log(response);
})
.catch(error => {
console.error('Error:', error);
});const makeQuery = (query) => {
const endpoint = url + query;
fetch(endpoint, { cache: 'no-cache' })
.then(response => {
if (response.ok){ // Check 200 status code
return response.json(); // Return response as json
}
throw new Error('Request failed!'); // Handle response error
}, networkError => {
console.log(networkError.message)
}).then(jsonResponse => {
console.log(jsonResponse)
});
}Last updated