hapi-namespace
v1.0.3
Published
Add namespace prefixes to Hapi routes, like express-namespace
Downloads
9
Readme
hapi-namespace
Add namespace prefixes to Hapi routes, like express-namespace
Install
Install from npm:
npm i --save hapi-namespace
Then require in your routing file:
var namespace = require('hapi-namespace')
Usage
namespace(prefix, routes)
prefix
is a string
routes
is an array of hapi route objects
Returns an array of routes, with the prefix prepended to each path.
Here's an example usage:
// This file is users/routes.js
'use strict'
var handlers = require('./handlers')
var namespace = require('hapi-namespace')
module.exports = namespace('/users', [{
path: '',
method: 'GET',
handler: handlers.find,
}, {
path: '',
method: 'POST',
handler: handlers.create,
}, {
path: '/{id}',
method: 'GET',
handler: handlers.findById,
}, {
path: '/{id}',
method: 'PUT',
handler: handlers.updateById,
}, {
path: '/{id}',
method: 'DELETE',
handler: handlers.removeById,
}])
This will export these routes:
GET '/users'
POST '/users'
GET '/users/{id}'
PUT '/users/{id}'
DELETE '/users/{id}'
Tests
Use npm test
to run the unit tests.