COVID-19 virus statistics
Data pulled from https://corona-stats.online on March 29, 2020. Today’s data reflects nearly 150,000 confirmed cases of COVID-19 within the United States. At the moment, everyone in the US has been advised to stay indoors, and promote social distancing.

One of my students showed me an API that returns near real-time data regarding the spread of COVID-19 (the “Corona Virus”). I’m not a medical p professional, but tracking COVID-19 virus statistics with code is a great way to remind yourself to practice good hygiene! In fact, think I might go wash my hands wright now!

Using your browser (client) send an HTTP GET to the API by clicking the link: https://corona-stats.online/

Alternatively, you could try using the curl utility against the API from a CLI terminal with the following command:

curl https://corona-stats.online/

Source code for the API is available on GitHub at: https://github.com/sagarkarira/coronavirus-tracker-cli

There is a help endpoint that documents that functionality of the API fairly well: https://corona-stats.online/help

Try to limit that data by accessing a path defined by a country. For example, to limit the results to “just” the United States: https://corona-stats.online/US

COVID-19 virus statistics by country
Data can be returned by the API per country by adding a /country or /countryCode path to the end of the API.

For statistics about the United Kingdom, try: https://corona-stats.online/UK

It you only wanted statistics about Italy: https://corona-stats.online/italy

Confirmed Cases Graph

If you prefer a visual representation of the data, as opposed to table driven data, you can use:

https://corona-status.online/[countryName]/graph or https://corona-status.online/[countryCode/graph.

For example, the following link will return graph data for the United States: https://corona-stats.online/us/graph

COVID-19 virus statistics graph
Data can be returned in a visual graph format by adding /[countryName]/graph or /[countryCode/graph to the end of the API lookup.

corona-stats.online API Parameters

By using API parameters, COVID-19 virus statistics may be returned in other formats. Parameters also offer the user the ability to limit results. For this API, parameters are handled in a simple key=value fashion, within the GET itself. Unfortunately, at the time of writing, I haven’t been able to get the ?json=true parameter to work. For me, the API still returns HTML table data.

Getting the top N countries is as easy as including, ?top=N at the end of the API. For example, if you wanted to view only the top 25 countries infected with the corona virus, you would query: https://corona-stats.online?top=25 Similarly, to return only the top 10 countries infected with the corona virus, you would query: https://corona-stats.online?source=1&top=10

By default, the API has multiple sources of data to draw from (at this time, two sources). A default source is always set, however, you can declare your own source with source=1 or source=2. For example, you can configure which source you want with:

How does an API work?

Consider what happened when you made that “click”:

BROWSER                          coronoa-stats.online API

HTTPS GET /  ----------------->
             <-----------------  200 + HTML Table Data 

First, your client (in this case, your browser) sends an HTTP GET to the corona-stats.online API. The API was designed to be ‘listening’ for HTTP GET messages, so the next step is the ‘acceptance’ of the GET by the API. Finally, the API returns an HTTP 200 with the HTML table data attached, populated with the current COVID-19 infection rates.

Links & References