Getting environment up and running for a simple RESTful API. Each microapi you want can be added as a separate self-contained plugin.
Can be run locally or installed and run via Docker/Docker Compose.
##Local Installation
- Clone repo
- Node / NPM developed & tested locally on v0.10.36, should work on anything higher (but not guaranteed).
- $cd into project directory
- $npm install
##Docker Installation
- Docker (boot2docker for OSX)
- Docker Compose
- Clone repo
##Run Tests
- From the project directory, run the command "$ npm test"
- If this command does not work you may need to globally install lab test library. $ npm install -g lab
##Run API Server Locally (Debug)
- From the project directory, run the command "$ npm run debug"
- Navigate in a browser to the index page at http://localhost:9011, which redirects you to the API documentation via Swagger) to view review and/or interactive utilize the API endpoints . or use e.g. curl http://localhost:9011/collect to hit the API endpoints
##Run API Server Docker-Compose(boot2docker) (Debug)
- The first time your run the hapiserver from docker-compose from the main project directory you need to run:
- "$ docker-compose build"
- "$ docker-compose up"
- Subsequently, from the main project directory, you can simply run the command
- "$ docker-compose start hapiserver" or "$ docker-compose start"
- To tail the docker logs:
- "$ docker-compose logs"
- To find the ip address where boot2docker is running your server\
- "$ boot2docker ip"
- Navigate in a browser to the index page at http://:9011, which redirects you to the API documentation via Swagger) to view review and/or interactive utilize the API endpoints . or use e.g. curl http://:9011/collect to hit the API endpoints
##Adding New Plugins
- Create a new directory under the /plugins
- Add 3 files
- index.js - Contains the registration for the plugin
module.exports.register = function (plugin, options, next) {
- Endpoint routes for the plugin Contains the registration for the plugin
plugin.route({ method: 'PUT', path: '/{id}', config: PluginFuncs.collectData });
- You need to have a route for each plugin for the index path for swagger to pick up the api in it's documentation
plugin.route({ method: 'GET', path: '/', config: { description: 'index', notes: 'Returns a index', tags: ['api'], handler: function (request, reply) { reply('plugin index'); } } });
+ ***funcs.js*** - Endpoint configuration and handlers
```javascript
module.exports.findAll = {
description: 'Get all',
notes: 'Returns all information. Can be filterd by an hour and minute passed in query string',
tags: ['api','list'],
handler: function (request, reply) {
reply('Plugin ' + request.method + " on " + request.path + " with " + request.query.hour +
" and " + request.query.minute );
},
validate: {
query: {
hour: Joi.number().min(0).max(23),
minute: Joi.number().min(0).max(59)
}
}
}
- package.json - Plugin meta information
{ "name": "publish-list", "version": "0.1.0" }