Answer can be found on Reddit
A simple project that creates a basic REST API to handle MongoDB documents via mongoose package, and provides Open API documentation as HTML page as well using it for route validation
One gets used to some kind of configurationless setup, and having an index
file in each folder allows one to import only the default, and have all objects named buy file name, so when adding a new model, engine or route, one only need to add one more file and do not worry about imports paths...
It uses an .http
file (found in the test
folder) that creates a POSTMAN alike query with the VS Code extension REST Client
One can run npm run docs
to generate an HTML file containing the API documentation
Open API schema is also been used to validate the routes by simple using it like this, an example response:
HTTP/1.1 400 Bad Request
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 348
ETag: W/"15c-XUvH2jFxzWx5DqpsVJkHgq3nQf4"
Date: Mon, 20 Feb 2023 00:27:49 GMT
Connection: close
{
"message": "Validation error",
"details": [
{
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params": {
"missingProperty": "title"
},
"message": "should have required property 'title'"
},
{
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params": {
"missingProperty": "imageUrl"
},
"message": "should have required property 'imageUrl'"
}
]
}
you can easily have a MongoDB instance using Docker, after install Docker Desktop or Rancher Desktop, run
docker run -d -p 27017:27017 --name mongoDB -d mongo:latest
and the application will then be able to connect via mongodb://localhost/<db_name>
connection string