


Description
This package allows a simple versioning scheme to be applied with Hapi servers.
Basic Usage
- Install package with:
npm install --save hapi-version
- Include it as a requirement for your server
server.register({
register: require('hapi-version')
}, function(err) {
if(err) {
throw err; //Bad things going on
}
});
- Declare your routes to have version information
server.route({
method: 'GET',
path: '/versioned',
handler: function(req, res) {
res('Hello world!');
},
config: {
plugins: {
versions: {
'1.0.0': true,
'2.0.0': function(req, res) {
res('Hello world 2.0!');
}
}
}
}
});
- When sending requests, include an 'Accept-Version' header with the proper version
curl --header "Accept-Version: 2.0.0" <host_url>/versioned
- If the requested version cannot be matched in the service, a
400
response (Bad Request) is returned
Advanced usage
More details on the project wiki.
Also, a look on the tests source code can be very enlightening
Running from source
- Check out the repository
- Use
npm test
to run the Lab test suite, including overall coverage statistics - Use
npm run coverage
to generate the Lab coverage report written to coverage.html
file - Use
npm run watch
continuously run the tests while editing the source code. It requires nodemon to be installed globally