backtrackbaba / covid-api

API's to interact with COVID19 dataset by John Hopkins University
https://covidapi.info/
MIT License
77 stars 19 forks source link

I'm using fetch and i'm unable to fetch only confirmed #18

Closed Sattishh closed 4 years ago

Sattishh commented 4 years ago

So I tried to use the latest cases of india and fetched that link, from that text, I wanted only the confirmed, recovered and deaths. I can't figure out how to get it. Can someone help me? Used node-fetch. .then(result => console.log(result["2020-04-11"].confirmed))) This is the code I tried, but it just shows TypeError. I used this because there were no , after result, 2020-04-11 and confirmed. Thank you!

backtrackbaba commented 4 years ago

Hi, @Sattishh

Here's how you could implement it using node-fetch

const fetch = require('node-fetch');

fetch('https://covidapi.info/api/v1/country/IND/latest')
  .then(response => response.json())
  .then(data => {
    date = Object.keys(data.result)[0]
    result = data.result[date]
    console.log(result)
  })
  .catch(err => {
      console.log('error')
  })

Let me know if you have any queries

Sattishh commented 4 years ago

That's awesome. Thanks a lot! Great API!