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

Fauna + Azure
This post discusses how to use Fauna and Azure Functions. …

Fauna+Azure Functions

child process in node
Hello guys, so today’s post would be centered on Node.js …

Delegating Tasks to child processes in Node.js

About The Author

Samson Amaugo

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

4 Comments

  1. Princess Oviawe

    Awesome write up.
    I haven’t done this before, but I Found it easy to follow.

    May 28, 2020
    • Sammy

      Thanks dear.

      May 30, 2020
  2. Mike c

    This is cool Sam. I like that steps are easy to understand

    May 28, 2020
    • Sammy

      Thanks Mike

      May 30, 2020

Leave a Reply

Cancel reply

Search Site

Recent Posts

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#

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 Swacblooms

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#
  • Hot Chocolate Data Loader: A Quick Guide
  • Exploring Policy-Based Authorization in Minimal API with .NET 8
  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫

Swacblooms🦋

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