The Covid-19 API provides current and historical Covid-19 data for every country in the world. Available data includes confirmed case counts and deaths, and is updated everyday.
HTTP GET
Returns either a time series of Covid-19 case counts/deaths for a country/region or a single-day snapshot of every country in the world (see parameters).
date
or country
must be set.date
- date to retrieve single-day snapshot. Must be in the form of YYYY-MM-DD
(e.g. 2022-01-01
)
country
- country name (case insensitive).
region
- (optional) administrative region (also known as state or province in many countries) name (case insensitive). Must be used in conjunction with country
. If not set, countries with data broken down by administrative regions will return separate data for each region.
county
- (optional) county name for US states (case insensitive). For United States data only. Must be used in conjunction with country
(United States
) and region
(e.g. California
).
type
- (optional) type of data to retrieve. Must be either cases
or deaths
. If not set, cases
will be used by default.
X-Api-Key
(required) - API Key associated with your account.
Live Demo!
https://api.api-ninjas.com/v1/covid19?country=
[
{
"country": "Canada",
"region": "Alberta",
"cases": {
"2020-01-22": {
"total": 0,
"new": 0
},
"2020-01-23": {
"total": 0,
"new": 0
},
"2020-01-24": {
"total": 0,
"new": 0
},
"2020-01-25": {
"total": 0,
"new": 0
},
"2020-01-26": {
"total": 0,
"new": 0
},
...
}
},
{
"country": "Canada",
"region": "British Columbia",
"cases": {
"2020-01-22": {
"total": 0,
"new": 0
},
"2020-01-23": {
"total": 0,
"new": 0
},
"2020-01-24": {
"total": 0,
"new": 0
},
"2020-01-25": {
"total": 0,
"new": 0
},
"2020-01-26": {
"total": 0,
"new": 0
},
...
}
},
...
]
import requests
country = 'canada'
api_url = 'https://api.api-ninjas.com/v1/covid19?country={}'.format(country)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
var country = 'canada'
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/covid19?country=' + country,
headers: { 'X-Api-Key': 'YOUR_API_KEY'},
contentType: 'application/json',
success: function(result) {
console.log(result);
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
}
});
const request = require('request');
var country = 'canada';
request.get({
url: 'https://api.api-ninjas.com/v1/covid19?country=' + country,
headers: {
'X-Api-Key': 'YOUR_API_KEY'
},
}, function(error, response, body) {
if(error) return console.error('Request failed:', error);
else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
else console.log(body)
});
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import com.fasterxml.jackson.databind.ObjectMapper;
URL url = new URL("https://api.api-ninjas.com/v1/covid19?country=canada");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
System.out.println(root.path("fact").asText());
let country = "canada".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: "https://api.api-ninjas.com/v1/covid19?country="+country!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()