API COVID-19 updated cases in Brazil
This project was created to have an updated API providing the data of COVID-19 cases in Brazil, according to the official site of the Ministry of Health. The project has been developed with Node.js and MongoDB and provides a REST API serving updated data of confirmed and deaths cases. In order retrieve the data from the Ministry web it is used a scheduled cron.
One of the main parts of the project is the automation for having the database updated. The code is at /src/app/services/UpdateService.js: The cron is scheduled to run everyday at 18:00h and 00:00h: the data of the official site is commonly updated around 18:00h, and in case this update delays for any reason it will be updated at midnight.
When the cron starts, using Pupeeter in order to navigate the site as a browser, it is examinate the last update time at https://covid.saude.gov.br/. If the time isn´t more recent than the stored update time at the database then nothing else is triggered, everything is up to date. Otherwise, if the update time is more recent than the stored time, the next step is triggered: The CSV file is downloaded (at a temporal folder) and it is parsed into an array of JSON objects to override the data stored at the database.
It is used Swagger to make a proper documentation of the API and capable of allow live tests. It is accessible at http://localhost:3000/docs in case you run the project at your computer.
The project uses Celebrate to implement validators at a middleware in order to check that the inputs of the requests are valid (at src/app/validators). Also it is used Jest to make both unit testing and integration (with database) testing using mocks.
The POST / PUT / DELETE methods of the API are reserved to registered users. To do this, is mandatory to register and have a valid JWT Token.
Finds and returns a state by its code (UF code).
GET /states/:code
Parameter | In | Type | Description |
---|---|---|---|
code |
path |
string |
Required. UF code of Brazil |
Responses
{
"name": string,
"code": string,
"region": {
"_id": string($uuid),
"description": string
},
"population": number,
"confirmed": number,
"deaths": number,
"officialUpdated": date
}
Status Code | Description |
---|---|
200 | Successful operation. State listed. |
400 | Bad request. Wrong State code. |
500 | Internal Server Error. Error finding the state. |
Finds and returns a region by its name (norte, nordeste, sudeste, centro-oeste, sul)
GET /region/:name
Parameter | In | Type | Description |
---|---|---|---|
name |
path |
string |
Required. Name of brazilian region |
Responses
{
"region": {
"_id": string($uuid),
"name": string,
"description": string,
"confirmed": number,
"deaths": number,
"states": [
{
"_id": string($uuid),
"name": string,
"code": string,
"population": number,
"confirmed": number,
"deaths": number,
"officialUpdated": date
},
{ ... }
]
}
}
Status Code | Description |
---|---|
200 | Successful operation. Region listed. |
400 | Bad request. Wrong Region Name. |
404 | Region not found. |
500 | Internal Server Error. Error finding the region. |