Giter Site home page Giter Site logo

ukhsa-internal / coronavirus-dashboard-api-javascript-sdk Goto Github PK

View Code? Open in Web Editor NEW
16.0 7.0 7.0 130 KB

Coronavirus (COVID-19) in the UK - API Service SDK for JavaScript

License: MIT License

TypeScript 100.00%
api-service coronavirus covid19 covid19-data govuk-service covid19-uk

coronavirus-dashboard-api-javascript-sdk's People

Contributors

xenatisch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

coronavirus-dashboard-api-javascript-sdk's Issues

getData does not have correct termination condition

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.

Incorrect example ...

The example structure parameters are invalid, resulting in a 404.

You should be using newDeaths28DaysByDeathDate and cumDeaths28DaysByDeathDate

Does not work with node app

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;

Requesting fewer records than one page causes infinite loop

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.

Example Page 1

Example Page 2

With API.getData looping until it receives a 204 or an error, this will now loop indefinitely:

https://github.com/publichealthengland/coronavirus-dashboard-api-javascript-sdk/blob/7ac7f6fbc06450a122ea446ee4fe78023eb4950d/lib/UKCovid19.ts#L120-L137

getJSON() call fails with 'unexpected end of file' error

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.