API: Show real data Covid19

Pedro Antunes
Nerd For Tech
Published in
3 min readApr 9, 2021

--

So in this tuturial we will demonstrate how to show covid-19 data (Portugal) between 29/03 to 03/04:

>List number of new cases (for all days of the week)
>List number of intensive care admissions (for all days of the week)
>Day with more new cases
>Day with fewer cases
>Average 7 days
>Total number of new cases in the week

So the first step is to crerate a folder for this project named CovidApi, then we will type the following commands in our Node.js command prompt:

npm init

npm install — save express body-parser mongoose

The next step is create the JavaScript files:

index.js
covidController.js
covidModel.js
covidRoutes.js

Then go to the following website:

https://covid19-api.vost.pt/

Select : “/Requests/get_entry/{date_1}_until_{date_2}”.

Click on the “try it out” and then on date_1 and set date 29–03–2021 and date_2 set date 4–4–2021 and finally, click on execute.

And then download the JASON file.

The next step isto open MongoDB Compass, and create a new database with following names:

The next step is to enter the created database, and click on Add data then import file and select input file type JSON and browse the file you previously download.

After the import the output should look like this:

The next step is coding our JavaScript files that we previously created.

Our Index.js file type the following code:

For the Controller file type the following code:

To the Model file type the following code:

For our Routes files type the following code:

The last step is to test our API on Postman.

The adress is http://localhost:6666/api/covid/

And the method is GET.

The output should look like this:

--

--