Socket
Socket
Sign inDemoInstall

hapi-namespace

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hapi-namespace

Add namespace prefixes to Hapi routes, like express-namespace


Version published
Weekly downloads
1
Maintainers
1
Install size
3.32 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 22 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc