Nefarious Plastic Mannequins

    hapi-namespace

    1.0.3 • Public • Published

    hapi-namespace

    NPM Version Build Status Coverage Status

    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.

    Install

    npm i hapi-namespace

    DownloadsWeekly Downloads

    4

    Version

    1.0.3

    License

    ISC

    Last publish

    Collaborators

    • dsernst