node.js: API COVID-19

Hi people!!

Today, I’m going to give you a tutorial to create an API on the most talked about pandemic right now, COVID-19.

This project that we are going to create will consist of a main file — index.jsand the MVC files. The objective will be to illustrate some revealing data in Easter week, namely the new daily cases and hospitalizations in intensive care.

But before we start on the project, is necessary to install the following programs:

mkdir apiCovid
cd apiCovid
npm init
npm install --save express body-parser mongoose
touch index.js
touch covidController.js
touch covidModel.js
touch covidRoutes.js

This page will be very important for the creation of this API because it is where we will get the necessary data to be placed in the database.

In addition, this is the ideal page for anyone who wants to create more API’s on COVID-19 data.

For this step, we will do the following tasks:

  1. Select the 2nd get: “/Requests/get_entry/{date_1}_until_{date_2}”;
  2. Click on the “try it out” button and then on date_1 set date 29–03–2021 and date_2 set date 4–4–2021 and finally, click on execute;

WARNING: Dates must be in the format shown in the following figure

Date format

After execution, it will show all data about COVID-19 included on those dates.

3. Click download (as shown in the following figure);

The file you have downloaded will come in JSON format.

Final aspect of the Database

Now, it’s time to program our API

Note: All JS files will have their code explanations as comments. This is going to be important to understand what each piece of code does.

So, let’s move on to the most important part of our API: the MVC

The final output will be something like this:

I hope you have succeeded and that you have learned something!!

Finalist student in Computer Engineering