Example API in Node.js using Service Template Node
This application is an example of creating a minimal service with Service Template Node and deploying it to the WMF infrastructure.
This Example API removes much of the Service Template Node boilerplate code, to show what a minimal service looks like and how it can be deployed. If you are looking for an example of how to do a particular thing, check Service Template Node.
To get the code and prepare for local execution/testing
- clone the repository
git clone "https://gerrit.wikimedia.org/r/mediawiki/services/example-node-api"
- install the dependencies
cd mediawiki-services-example-node-api
npm install
To try the service locally
- launch the service
npm start
- invoke the "hello" endpoint (either in your browser or via something like curl)
http://localhost:6927/hello
The Example Node API includes tests from Service Template Node, as well as its own test. To execute tests, run:
npm test
The Example Node API demonstrates how to keep your APIs documentation up to date.
Each route definition should have an @openapi annotation with an OpenAPI-specification compliant YAML description. When updating or adding any routes, a git hook will execute
npm run doc
to ensure the OpenAPI spec in /static/spec.json is properly updated.
You can solve many issues by recreating the node_modules directory:
rm -r node_modules
npm install