COVIDSymptomReportAPI

Free to use under the Unsplash License Link
  • Swagger: Interface Description Language for describing RESTful APIs expressed using JSON.
  • Microsoft Azure: commonly referred to as Azure, is a cloud computing service created by Microsoft for building, testing, deploying, and managing applications and services through Microsoft-managed data centers.
  • GraphQL: a open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.

[ API Architecture]

In a some way to say it, after we have the initial code for the API to work, we have:

  • controller .js files: it handles incoming HTTP requests and send response back:
  • connector.js: it handles the MongoDB database process's as respective functions on it;

[ Curiosities ]

As the project was developing, we came across with some interesting ideas where we try to learn more than we expected, so don’t be surprise if encounter some content out of context from the original objective. For example, as we know a API output is intended for machines to understand but for simple API’s we could process the output for human read friendly. So, in some of the end-points that we developed we did coded in a way that the output given would be processed to do that. You can see more about that as you continue to read this article.

[ Connecting API to MongoDB ]

In relation of the API, having a account on the MongoDB where we will use a cluster and the respective link to connect our application to it. In the link provided by the cluster we have to considering three things like username, password and the database name where we will put these values in the nodemon.jsonfile to turning them into environment variables.

[ Initializing the API ]

Having the Visual Studio Code installed on a machine, we create a tree of directories and files as showed below:

COVIDSymptomReportAPI                           [directory]
├── controllers [directory]
│ ├── authentication_controller.js [file]
├── development_controller.js [file]
├── reports_controller.js [file]

├── custommodules [directory]
│ ├── classes.js [file]

├── graphql [directory]
│ ├── resolvers [directory]
│ │ ├── index.js [file]
│ ├── schema [directory]
│ ├── index.js [file]

├── models [directory]
│ ├── report.js [file]

├── routes [directory]
│ ├── development_route.js [file]
│ ├── general.js [file]
│ ├── reports_route.js [file]
├── connector.js [file]
├── index.js [file]
├── nodemon.json [file]
npm install -save express mongoose swagger-jsdoc@6.0.0 swagger-ui-express node-json2html express-graphql graphql mongodb npm install nodemon -D
  • mongoose: Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.
  • swagger-jsdoc@6.0.0: reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.
  • swagger-ui-express: allows you to serve auto-generated swagger-ui generated API docs from express, based on a swagger.json file. The result is living documentation for your API hosted from your API server via a route.
  • node-json2html: an open source javascript library that uses js templates to render JSON objects into HTML.
  • express-graphql: a GraphQL HTTP server with any HTTP web framework that supports connect styled middleware, including Connect itself, Express and Restify.
  • graphql: JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
  • mongodb: The official MongoDB driver for Node.js.
  • nodemon -D: a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected (as a development dependency).

For a article friendly read purposes, we will post all code of each file related to this project in the end of this article.

[ Deploying ]

[ Microsoft Azure]

After having the project completed, we did use the Visual Studio Code with the Azure extension to deploy our API.

[ Heroku ]

As done in Azure, we decided to learn the deploying of the API in the Heroku, that it works similarly.

[ Running It ]

As the both servers are running, we will show examples of the running API using the Heroku link provided.

[ COVIDSymptomReportAPI ]

[ Swagger ]

[ End-Points ]

1. [ Authentication ]

This one it permits to Register a New User, Login and Logout. The authentication protects the other end-points sections as Public, Reports, Overview and Development Sections:

2. [ Public ]

This end-point as the purposes to create a new register and stores it into the database:

3. [ Reports ]

As the purpose to analyse data related of Reports stored in the database:

3.1 [ GetAllReports End-Point ]

This end-point it gets all reports stored in the database:

3.2 [ ReportsCount End-Point ]

This one it gives the total number of existing Reports:

3.3 [ GenderCount End-Point ]

This end-point returns the total number of a specific gender type:

3.4 [ VacineGenderCount End-Point ]

With this one we can get a analysis related to type of gender and the vaccination:

3.5 [ AgeRangeCount End-Point ]

It gets the number of Reports related to various ranges of age:

3.6 [ CustomAgeRangeCount End-Point ]

In this one we can specify a custom age range to retrieve the total number of Reports:

3.7 [ VaccineCount End-Point ]

Retrieves the total number of Reports with the vaccination related:

3.8 [ ChronologicalCount End-Point ]

Returns the number of Reports related to Year, Month and Day:

3.9 [ CustomChronologicalReport End-Point ]

It shows the Reports and number with a specific range of Date (Year, Month, Day) and Time (Hour, Minutes):

3.10 [ ReinfectionCount End-Point ]

Returns the number of people that answered that have been infected before and suspect to be having symptoms by Year, Month and Day:

3.11 [ SymptomRation End-Point ]

This end-point gives a analysis related to a specific chosen symptom, and the percentage of the Reports:

4. [ Overview ]

In this section it has the Overview end-point that it shows a summary of all early end-points. As similar as the GetAllReports end-point, it returns a html code for human read friendly. For development time consumption reasons, we only work on the adaptation of four of the above functions.

5. [ Development ]

In the development section we had created a end-point that generates a specific amount of fictional data and it stores into the database for testing purposes. We input the number of Reports to be created as parameter.

[ GraphQL ]

As a optional requirement, we did implement the GraphQL into our API. Returning to the homepage, we choose the GraphQL interface that will present us the following page:

José Costa & Dylan Pinto.

COVIDSymptomReportAPI_controllers_authentication_controller.js

COVIDSymptomReportAPI_controllers_development_controller.js

COVIDSymptomReportAPI_controllers_reports_controller.js

COVIDSymptomReportAPI_custommodules_classes.js

COVIDSymptomReportAPI_graphql_resolvers_index.js

COVIDSymptomReportAPI_graphql_schema_index.js

COVIDSymptomReportAPI_models_report.js

COVIDSymptomReportAPI_routes_development_route.js

COVIDSymptomReportAPI_routes_general.js

COVIDSymptomReportAPI_routes_reports_route.js

COVIDSymptomReportAPI_connector.js

COVIDSymptomReportAPI_index.js

COVIDSymptomReportAPI_nodemon.json