JSFiddle - React, Tailwind, and code Playground
by Owain Stratton
HTML
<button id="fetchBtn">
FETCH
</button>
JavaScript
document.getElementById('fetchBtn').addEventListener('click', function() {
var apiKey = 'test';
var headers = new Headers();
headers.append('Accept', 'application/json');
var config = {
method: 'GET',
mode: 'cors',
cache: 'no-store',
headers: headers
};
fetch('https://content.guardianapis.com/search?api-key=' + apiKey, config)
.then(function(response) {
response.json().then(function(responseObject) {
console.log(responseObject.response);
});
})
.catch(function(error) {
then(function(errorObject) {
console.log(errorObject);
});
});
});