Swacblooms🦋

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Programming
Making a Corona Data Fetcher (API)
Programming

Making a Corona Data Fetcher (API)

Samson Amaugo May 27, 2020

Hello, you are welcome to read this post. I’m sure most of you reading this post have made use of an app or website that gives you updates on the spread of the Corona Virus. You might have asked yourself the question of how these applications have access to this data.

How this happens is that they make use of something called an API (Application Programming Interface). Basically, an API is an interface that allows two applications to communicate. They can be in the form of a URL, a native method on a device etc.

In this post, I would be describing how to build your own API that can provide access to the information regarding the Corona Virus.

Hence, let me describe how this build works:-

  • We would scrape a website called Worldometer. It provides realtime stats on various data.
  • Once we scrape the data, we parse the HTML elements to get what we want
  • We use the data to construct an object
  • Then we build two endpoints to respond to requests.

Create a new directory and type “npm init -y” in the command line.

Run npm install express, node-fetch, cheerio. These are the dependencies we would use to build this API.

Express would help make handling of request easy, node-fetch would give us similar methods to the fetch API on the browser which most devs like, cheerio is the library we would use to parse the HTML returned from using the node-fetch library to make a request to the site.

Before we continue I would like you to know that I used my chrome dev tools to inspect the site (https://www.worldometers.info/coronavirus/).

The reason for this is because for me to parse the data in the HTML correctly, I need to know where each required item is located in the HTML tree.

The cheerio library used looks a lot like jquery. So this post would be easy for you to understand if you’ve used jquery.

The block of codes below contains the details and implementations used to make this API with comments that helps explain what I did.

Create a file called data.js, it would contain the code that handles fetching of the data for a specific country.

Create a file called countries.js, it would contain the code that handles fetching of the data that displays countries that you can query for

Finally, create the index.js file. This file would handle the routes and request from a client.

Then run “node index.js”. This would start the server and you can try and make a request from your browser.

To get the Corona Virus information for a specific country. Run this in your browser:- localhost:3000/{your country}

To know the countries you can query for using this API, run this in your browser:- localhost:3000/list/countries

Thanks for following through, please if you have any contribution or question you can leave that in the comment section. Thanks

You can check out this GitHub repo to see the files used in this post by clicking here

Prev Article
Next Article

Related Articles

mocking the httpclient
Hello everyone, in today’s post I would be talking about …

Mocking the HttpClient in C#

adjusting your processor speed in ubuntu
Hello guys, in this post I would be putting down …

Adjusting your processor speed in Ubuntu

About The Author

Samson Amaugo

I am Samson Amaugo. I am a full-stack developer and I specialize in DotNet and the MERN stack.

Search Site

Recent Posts

  • Cloudflare Tunnel to Postgres, plus Swarm’s static IP problem
  • The Topological Sort
  • Building a Perceptron in .NET
  • Part 4 — Assertions: Verifying What You See
  • Part 3 — Actions and Auto-Waiting: Putting Locators to Work

Categories

  • EDUCATION
  • Motivation
  • Programming
  • Uncategorized

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

we respect your privacy and take protecting it seriously

RSS feed: Swacblooms Swacblooms

Swacblooms🦋

Making the Moves
Copyright © 2026 Swacblooms🦋
Swacblooms - Making the Moves