The spread of the Coronavirus has affected every walk of life. The world is still recovering despite the development of new vaccines. Many businesses disappeared overnight, and some are still counting the cost. The pandemic has claimed 3.8 million lives and infected 176 million people worldwide at the time of writing.
As per health experts, Covid-19 parallels the 1918 Spanish Flu – which was also a contagious respiratory illness that had infected about one-third of the world’s population and is still considered the deadliest event in human history as it had killed around 50 million of its victims.
Governments across the world had to take drastic measures to curb the spread of the virus – by imposing travel restrictions to a complete lockdown. The use of digital technologies played a crucial role in building the knowledge required in making critical decisions, and Technologists around the globe raced against time to develop apps and services for tracking COVID-19.
One such service is Covid-19 Data API which provides reliable statistics about Coronavirus that are updated every 15 minutes. It allows data scientists and technology enthusiasts to build real-time Coronavirus Tracker Dashboards and Apps.
It’s recommended to go through this post at first – if you are new to the APIs.
What is Covid-19 Data API?
Covid-19 Data API is a set of REST APIs that provides the global and country-level COVID-19 cases and deaths.
The API server collects data from several reliable sources and has six servers worldwide, providing near real-time statistics about Coronavirus.
Using Covid-19 Data API, users can build interactive dashboards for coronavirus tracking with the following functionalities.
- Display daily report for overall coronavirus cases (confirmed, recovered, and deceased)
- Update Latest statistics after every 15 minutes.
- Get Daily Report for All Countries
- Get Daily Report by Country
- Get Latest Report by Country
- Display List of all countries
The API has a free plan which allows fetching total and country-wise statistics if your usage is under 50k requests /month.
It also offers a Pro plan where you can make unlimited requests, but there’s a rate limit of 20 requests per second.
Suppose you are aiming for a high-traffic application. In that case, you can subscribe to its ‘Ultra’ plan, which doesn’t have any rate limit or monthly quota. It also gives you access to the “Get all Countries’ endpoint – allowing you to see data for all countries in just one request.
How does the COVID-19 Data API work?
COVID-19 Data API is based on REST Guidelines. It provides several endpoints that can be executed over the web using the language and framework of your choice, and it works in the following way.
The client issues a GET request to one of its endpoints. The API server responds with the requested data in a JSON format.
The Below diagram illustrates the high-level overview of the COVID-19 Data API.
Who can use the COVID-19 Data API?
News Websites and Media Outlets
Since the early days of the COVID-19 outbreak, news websites started adding widgets to their websites containing information about Coronavirus spread. The information about the cases sometimes had to be entered manually (in their backend systems) as official websites wouldn’t provide API that can be integrated with the website or an app. However, with COVID-19 Data API, the statistics about COVID-19 on such websites can be fully automated.
Media Outlets can also use this API to gather the data from reliable sources, which is updated in near real-time, i-e after every 15 minutes. This way, their visitors will always be up to date about the coronavirus situation in their region.
Web and Mobile Application Developers
COVID-19 Data API is best suited for the developers aiming to build Coronavirus Tracker Dashboard. The API can be seamlessly integrated into the web or mobile application to provide the latest data about the coronavirus outbreak. The API provides data for all countries, allowing developers across the world to build coronavirus tracker dashboards for their country.
Data Scientists
As the pandemic raged, Data Scientists across the world built various regression models by utilizing AI-based algorithms and the Covid-19 data sets. Services like COVID-19 Data API can be consumed by data scientists in creating those predictive models. They can build their machine learning model based on historical data and test it as it provides daily reports for all the countries.
How to Connect to COVID-19 Data API Tutorial – Step by Step
RapidAPI makes it super easy to connect with the COVID-19 Data API. Using its powerful API Console, you can connect to thousands of APIs using the single API key. It also allows you to generate the code snippet in many popular programming languages and execute the endpoints without leaving the browser.
The process can be summarized as below:
Step1: Signup for an Account on RapidAPI
First, you need to create an account on RapidAPI (where you can find and connect to thousands of APIs using One SDK and one API Key).
Step2: Search the API Marketplace
After successful registration, you will be redirected to the dashboard. Navigate to “API Marketplace” and search for “COVID-19 Data API“.
Select the API by clicking on the “COVID-19 Data”. It will redirect you to the API Home Page.
Step 3: Subscribe to the API
Navigate to the ‘Pricing’ page of the COVID-19 Data API to subscribe to the API. You can select the appropriate plan as per your business requirements and then click on the ‘Subscribe’ button to subscribe to that plan.
Step 4: Test the API
Now that you have successfully subscribed to the API, you can begin testing its endpoints. Navigate to the ‘Endpoints’ tab and select the ‘getDailyReportTotals’ endpoint.
You would notice that RapidAPI Console automatically generates the required header parameters like API Key and Host information. You can click on the ‘Test Endpoint’ button to execute the request.
You should see the API response in the Results tab (as shown in the below image).
Note: In case of any failure, the COVID-19 Data API may return one of the following responses:
- 400 Bad Request – Client sent an invalid request (missing required parameters).
- 401 Unauthorized – Failed to authenticate with the API server.
- 403 Forbidden – The client authenticated but didn’t have permission to access the required resource.
- 404 Not Found – The requested resource (endpoint) doesn’t exist.
- 500 Internal Server Error – A generic error occurred on the API server.
- 503 Service Unavailable – The API service is not available.
COVID-19 Data API uses ISO 3166-1 Standard for country code, and if the provided code is invalid, it will return the JSON response containing the error message.
Explanation of the COVID-19 Data API Endpoints
The COVID-19 Data API Endpoints are categorized into three groups.
- Country: This contains all the endpoints to fetch the statistics per country.
- Totals: All the endpoints to fetch global data are added to this group.
- Help: This includes helping endpoints such as OpenAPI Documentation and getting a list of all countries.
In the following section, we will explore these endpoints in detail.
GetLatestAllCountries
This endpoint provides the latest statistics for Coronavirus for all countries. It has one optional parameter called ‘format’, which can be used to specify the format of the response – It can contain only two values, ‘ XML and JSON.’
The API response includes the array list of all countries and their covid-19 data, such as confirmed cases, recovered, critical, and deaths.
Below is the sample response when this endpoint is executed.
GetDailyReportAllCountries
This endpoint allows you to view the daily report of the spread for all countries. However, it has a required parameter, ‘date’, which filters the API response. It is super helpful in situations where historical data is needed.
Note: The API response returns a list of countries that contain COVID-19 data for each province.
GetLatestCountryDataByName
This endpoint provides the latest statistics for any given country. It requires a country name and returns a JSON formatted response containing the COVID-19 data, including the ‘lastchange’ and ‘lastupdate’ fields.
GetDailyReportByCountryCode
This endpoint provides a daily situation update about Coronavirus for any given country. It requires country code (in ISO 3166-1 format ) and the date of the report. It can also provide historical data. Below is the sample response.
GetDailyReportByCountryName
This endpoint also provides a daily report for Coronavirus, but it doesn’t require any country code. Users can pass the country name in string format, and it will return the coronavirus statistics of that country.
For instance, it returns the following response when executed for the country: Italy.
GetLatestCountryDataByCode
This endpoint also provides the latest statistics about Coronavirus for a given country. However, it requires the country code (in ISO 3166-1 format) instead of the name.
Below is the response when it’s executed for the United Kingdom.
GetDailyReportsTotals
This endpoint provides the statistics for the global COVID-19 cases, recovery, and deaths. It has an optional date parameter that can be used to fetch historical data as well.
GetLatestTotals
This endpoint doesn’t require any parameter and returns the latest global statistics. Below is the sample response.
OpenAPIDocumentation
COVID-19 Data API conforms to Open API Specifications, allowing users to view the meta-data and documentation about its API using this endpoint. This endpoint contains valuable information about the API, such as available endpoints, summary, tags, description, parameters, and responses.
GetListOfCountries
This endpoint returns the list of all countries along with their ISO codes in ‘alpha2code’ and ‘alpha3code’ formats.
COVID-19 Data API can be used with all popular programming languages and frameworks. Using RapidAPI Dashboard, you can generate code snippets for any programming language using various libraries. The following section will explore how it can be integrated with Python, PHP, Ruby, and JavaScript.
How to use COVID-19 Data API with Python
To run the Python application, make sure that you have installed the Python application. You can use any client library to use COVID-19 Data API.
The following code snippet uses http.client to fetch the latest report of global cases using COVID-19 Data API.
import http.client conn = http.client.HTTPSConnection("covid-19-data.p.rapidapi.com") headers = { 'x-rapidapi-key': "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541", 'x-rapidapi-host': "covid-19-data.p.rapidapi.com" } conn.request("GET", "/totals?format=json", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
How to use COVID-19 Data API with PHP
Before running the sample code shared below, please make sure that you have installed PHP. You may follow this guide on how to install this correctly.
The below code example also executes getLatestTotals endpoint to fetch latest report of global cases.
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://covid-19-data.p.rapidapi.com/totals?format=json", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: covid-19-data.p.rapidapi.com", "x-rapidapi-key: ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
How to use COVID-19 Data API with Ruby
The below example uses Ruby. Please make sure that you have installed Ruby on your system.
require 'uri' require 'net/http' require 'openssl' url = URI("https://covid-19-data.p.rapidapi.com/totals?format=json") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541' request["x-rapidapi-host"] = 'covid-19-data.p.rapidapi.com' response = http.request(request) puts response.read_body
How to use COVID-19 Data API with Javascript
To use the API in JavaScript, you need to first set up the JavaScript environment. You can download text editors such as Atoms, Visual Studio Code, NotePad++, etc.
The following code snippet invokes the DailyReportByCountryCode endpoint to fetch the daily statistics for the United Kingdom.
fetch("https://covid-19-data.p.rapidapi.com/report/country/code?code=GB&date=2020-04-01", { "method": "GET", "headers": { "x-rapidapi-key": "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541", "x-rapidapi-host": "covid-19-data.p.rapidapi.com" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
The API successfully returns the requested data as shown below.
Benefits
Speed
COVID-19 Data API has a latency of just 89 milliseconds at the time of writing, making it ideal for integrating with high-performance websites and apps.
Reliability
The fight against COVID-19 is highly dependent on reliable data and statistics. Everyone in our society wants to know the latest news about the pandemic, the number of newly infected persons, recovery and death rates. Unreliable or insufficient information often leads to speculation and impaired decision-making. COVID-19 Data API addresses these concerns by taking data from trusted sources and updating it after every 15 minutes.
Historical Data
COVID-19 Data API allows users to view historical data as well. It opens up opportunities for data scientists, epidemiologists, and developers to use this data for various purposes, such as predictive modeling using machine learning and AI or displaying historical charts and graphs.
Alternatives to COVID-19 DATA API
There are some alternatives to COVID-19 Data API, which are described below.
- Coronavirus Smartable API: This API allows users to fetch statistics and news about Coronavirus per country or state.
- COVID-19 Statistics API: This API is based on public data by Johns Hopkins CSSE and provides an overview of the global cases.
- COVID-19 Tracking API: This is the Free API that uses the scraping technique to fetch the live statistics from the Worldometers.com website.
- Coronavirus Map API: This API provides free covid-19 live updates and also provides historical data, maps, charts, and graphs.
Summary
This article explored how COVID-19 Data API can be used with various web and mobile applications to build a variety of applications, from interactive dashboards to news websites and predictive modeling. We have also discussed the endpoints it offers and how they can be integrated using popular programming languages such as Python, PHP, Ruby, and JavaScript.
Leave a Reply