0.1.5 • Published 7 years ago

hapi-nested-route v0.1.5

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

hapi-nested-route

add nested function to hapijs route

npm version

You can use this plugin to add nested function to your hapi routes.

Usage

Example:

const server = new Hapi.server()

const plugins = [
  ...
  {
    register: require('hapi-nested-route'),
  },
  ...
];

server.register(plugins, (err) => {
  ...
})

// you can also use default route function.
server.route({
  path: '/api/ok1',
  method: 'get',
  handler: (request, reply) => {
    reply('ok1');
  }
});

// do nest!
const nestedRoute = server.route.nested('/api')
nestedRoute({
  path: '/ok2', // generated path is /api/ok2
  method: 'get',
  handler: (request, reply) => {
    reply('ok2');
  }
});

// you can route with arguments.
// nestedRoute[method](path: String, config: Object, handler: () => {})
// methods: get, post, put, del, any
nestedRoute.get('/ok3/{id}', { // generated path is /api/ok3/{id}
  validate: {
    params: {
      id: Joi.number().integer().required(),
    },
  }
}, (request, reply) => {
	reply(request.params.id)
})

// you can also nest from already nested router
const doubleNestedRoute = nestedRoute.nested('/user')
doubleNestedRoute({
  path: '/show', // generated path is /api/user/show
  method: 'get',
  handler: (request, reply) => {
    reply('howdy!')
  }
})
0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago