An example of consuming an external API... This is the 'Datasets' list from the UK ONS (Office for National Statistics) More Info...
...more content will come onstream shortly
const fnRenderDatasets = (result) => {
console.log('fnRenderDatasets', result);
const oContext = document.getElementById('context');
oContext.textContent = result['@context'];
const oResults = document.getElementById('results');
for (item of result.items) {
console.log(item);
const newLi = document.createElement('li');
newLi.textContent = item.description;
newLi.classList = 'list-group-item small';
oResults.append(newLi);
};
};
const fnGetData = (src) => {
console.log('fnGetData Started, Source:',src);
fetch(src)
.then((result) => {
console.log('fnGetData Complete, Source:',src);
return result.json();
})
.then((result) => {
fnRenderDatasets(result);
console.log(result);
})
.catch(function(error) {
console.log(error);
});
};
fnGetData('https://api.beta.ons.gov.uk/v1/datasets');