I am trying to learn how to request JSON data with the JavaScript Fetch-API to fetch data from an open data portal called CKAN.
Following the Google documentation I tried this code:
fetch('https://ckan.open.nrw.de/api/3/action/package_list')
.then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
This function catches an object Error (when opening the URL in my browser, I get a valid JSON):
"Fetch Error :-S", [object Error] { ... }
What is the problem here?
Here is a working jsfiddle.