How to Build a Real-Time Pandemic Tracker App Using Public APIs

Tracking pandemic data in real time is easier than ever thanks to public APIs. By combining a simple frontend with a reliable data source like the Disease.sh API, you can create a live dashboard that shows confirmed cases, recoveries, and deaths for any country. This tutorial walks you through the core steps.

First, choose an API that provides pandemic statistics. Disease.sh (https://disease.sh) is free, requires no API key, and returns JSON responses with country-level data. You can fetch global totals, country-specific info, or historical trends using endpoints like https://disease.sh/v3/covid-19/countries.

Article illustration

1. Set Up Your Project Skeleton

Create a single HTML file with embedded CSS and JavaScript. No frameworks are required. Structure your page with a country selector input, a “Track” button, and a results area to display stats. Keep the layout minimal — a clean card design works well.

<input type="text" id="country" placeholder="Enter country name">
<button id="trackBtn">Track</button>
<div id="results"></div>

2. Fetch Data from the API

Use the fetch() function in JavaScript to call the Disease.sh endpoint. When the user clicks the button, build the URL with the entered country name. Handle the response by converting it to JSON and extracting fields like cases, deaths, recovered, and active.

document.getElementById('trackBtn').addEventListener('click', async () => {
  const country = document.getElementById('country').value;
  const url = `https://disease.sh/v3/covid-19/countries/${country}`;
  const res = await fetch(url);
  const data = await res.json();
  // Update UI with data.cases, data.deaths, etc.
});

3. Display and Refresh Dynamically

Create a function that updates the HTML elements inside #results with the fetched numbers. Use template literals to build a simple layout. Add error handling for invalid country names. Optionally, use setInterval() to refresh data every 60 seconds, making the tracker truly real-time.

4. Enhance with Visual Feedback

Improve the app by adding a loading spinner during fetches and color‑coding numbers (e.g., red for cases, green for recovered). You can also integrate Chart.js to plot historical trends, but keep the core app functional first.

Building a pandemic tracker app is a great way to learn API integration and asynchronous JavaScript. Start with the basics, then extend with country comparisons or map overlays. The Disease.sh API gives you all the data you need — go ahead and build your real-time dashboard today.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *