CORONAVIRUS API

JavaScript Example

The simplest way to get started with JavaScript

Simply copy-paste the code below, replace your API key, and you're ready to start using our data, within less than 30 seconds.

Don't forget to add your own API key in the code (you will receive it once you sign up for a plan).


Dynamically display the numbers in a text for a specific location

See demo

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){


            /**
             * GET THE CASE NUMBERS FOR A COUNTRY
             */
            // Replace the API_KEY with your own API key that we provide once you sign-up here: https://coronavirusapi.dev/#pricing
                $.get("https://api.coronavirusapi.dev/countries/gb/?key=API_KEY", function(data, status){
                    console.log(data);

                    $('#country_cases_number').html(data.cases);
                    $('#country_deaths_number').html(data.deaths);
                });

            /**
             * GET THE CASE NUMBERS FOR A LOCATION
             */
            $.get("https://api.coronavirusapi.dev/cities/us/california?key=API_KEY.", function(data, status){

                    $('#location_cases_number').html(data.cases);
                    $('#location_deaths_number').html(data.deaths);
                });
        });
    </script>
</head>
<body>
<!--The div below will be populated after the data is retrieved from our API-->
<span id="cases_number"></span>

<p>
    In the United Kingdom there are currently <span id="country_cases_number"></span> cases of coronavirus and a total of <span id="country_deaths_number"></span> deaths.
</p>

<p>
    In California, US there are currently <span id="location_cases_number"></span> cases of coronavirus and a total of <span id="location_deaths_number"></span> deaths.
</p>

</body>
</html>
            


By choosing a plan below, you confirm that you have read, understood and accepted our terms and conditions.