API Implementation Overview - OpenDataEnterprise/sdg-nri-website GitHub Wiki
Introduction
The UN SDG National Reporting Initiative API is an internal API to provide an interface between the project's website and database. The website cannot communicate with the database directly, necessitating the API.
The API receives and parses requests from the website, then retrieves the appropriate data from the database and converts them into JSON format before returning them as a response to the website's requests.
The API also provides endpoints for processing the forms submitted from the website. A detailed description of the forms available on the website can be found in the API Form Handling page.
The GitHub repository for the API can be found at https://github.com/OpenDataEnterprise/sdg-nri-api.
Integration with Forest Admin
Forest is an SaaS (Software as a Service) admin panel that provides an easy-to-set-up interface for users to interact with their databases.
An API microservice was generated by using Forest Lumber to allow Forest to communicate with the project database. The SDG National Reporting Initiative API was extended on top of the generated microservice, and is all written using Express framework.
Middleware for Forest API endpoints should be located under routes/forest/
. You can learn more about Express middleware in the official documentation.
Sequelize ORM
Since the generated API utilizes Sequelize as an ORM (object-relational mapping) framework, the internal API also makes use of Sequelize out of convenience. With Sequelize, you define intermediate data models that allow you to interact with your database in a more abstracted and convenient manner.
The models should be located under the models/
directory. These models should largely mirror the existing database schema.
Internal API
The internal API endpoints that the website interacts with are defined under routes/api/v1/
.
express-validator
is used to provide parameter validation.