Search code examples
javascriptnode.jsjsonfetch

Is there a way to fetch an object inside a JSON object from a URL?


I want this object for a Covid-19 online chart:

https://pomber.github.io/covid19/timeseries.json

But as you see, it weighs 7.2Mb, and so I'd like to make a petition to the server in which it only returns one of the countries instead of all of them.

Something like

fetch(https://pomber.github.io/covid19/timeseries.json.UnitedStates , {})

The second option is to download the file every day and make my server handle the JSON and split it into a JSON for each country. The question is if I can make this an automated process with a nodeJS server. In case I have to do this, do you have any idea how can I automate the download and split it in a Debian 10 server with NodeJS in the backend?


Solution

  • No, that's not possible unless the server from which you are retrieving the file provides an API like this. What you describe would be a good use-case for GraphQL, but again, that's something the server, in this case github.io, would need to implement.

    Regarding daily fetching: yes, of course, and there are tons of examples of that on the web. Please try them and if it doesn't work, update your question with specific code that doesn't work for you.

    As for Covid-19 data, I recommend you take a look at the JHU repo directly. They offer data in smaller bites, too.