ukhsa-internal / coronavirus-dashboard-api-javascript-sdk Goto Github PK
View Code? Open in Web Editor NEWCoronavirus (COVID-19) in the UK - API Service SDK for JavaScript
License: MIT License
Coronavirus (COVID-19) in the UK - API Service SDK for JavaScript
License: MIT License
The termination condition in the getData loop is incorrect - calling the API with an invalid page number will result in a 404, not a 204.
The loop termination condition is when data.pagination.next is null on return from the Axios get.
The example structure parameters are invalid, resulting in a 404.
You should be using newDeaths28DaysByDeathDate and cumDeaths28DaysByDeathDate
Hi,
Your example does not work in a node.js app. The following error is generated:
const api = new Cov19API({
^
TypeError: Cov19API is not a constructor
I think it may be to do with the way that you transpire your typescript?
What does work is adding ".default" to the require():
const Cov19API = require('@publichealthengland/uk-covid19').default;
When making a request that results in fewer results than contained in a single response of the API, request will be repeated infinitely.
See example below:
const structure = {
date: 'date',
areaName: 'areaName',
cumPeopleVaccinatedFirstDoseByPublishDate: 'cumPeopleVaccinatedFirstDoseByPublishDate',
};
const filters = ['areaType=nation'];
const api = new Cov19API({
filters,
structure,
latestBy: 'cumPeopleVaccinatedFirstDoseByPublishDate',
});
I would expect this to have been caused by a change to the API that means page 1 returns the same result as page 2. As can be seen in the below examples.
With API.getData
looping until it receives a 204 or an error, this will now loop indefinitely:
While attempting to use this in Node (14.13.1 FWIW), I get the following error...
(node:92897) UnhandledPromiseRejectionWarning: Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (zlib.js:180:17)
...with the following code:
const Cov19API = require('@publichealthengland/uk-covid19').default;
(async () => {
const casesAndDeaths = {
date: 'date',
areaName: 'areaName',
areaCode: 'areaCode',
newDeaths28DaysByDeathDate: 'newDeaths28DaysByDeathDate',
};
const englandOnly = ['areaType=nation', 'areaName=England'];
const api = new Cov19API({
filters: englandOnly,
structure: casesAndDeaths,
});
const data = await api.getJSON();
console.log(data);
})();
I've added .default
per #1 and updated the metrics per #3 in this code already. I did add an await
before api.getJSON()
, since that returns a promise.
As best as I can tell from debugging this, the error seems to come from the axios call in this.head(), triggered at the end of getJSON, when the API returns status code 204. Wasn't able to solve the problem though.
As a workaround, calling getCSV
doesn't have this problem (because it doesn't make a HEAD request).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.