Skip to content

This is a resource function created for hapi.js in order to in order to reduce the amount of boilerplate code when writing hapi routes.

License

Notifications You must be signed in to change notification settings

sakoh/hapi-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapi-resource

This is a resource function created for hapi.js in order to in order to reduce the amount of boilerplate code when writing hapi routes.

###INSTALLATION

npm install hapi-resource

##USAGE

Given an API controller:

var PostsController = {

  index: function(request, reply) {
   ....
  },

  show: function(request, reply) {
    .....
  },

  create: function(request, reply) {
    .....
  },  
}

you can now write:

server.route(
  resource({
    name: 'post',
    controller: PostsController
  })
);

Instead of writing:

hapiServer.route([
  {
    method : "GET",
    path : "/posts",
    handler : PostsController.index
  },
  {
    method : "GET",
    path : "/posts/{id}",
    handler : PostsController.show
  },
  ...
]);

You can also easily namespace your routes:

var resource = require('hapi-resource');

server.route(
  resource({
    name: 'user',
    controller: UsersController,
    namespace: '/admin'
  })
);

is equivalent to:

hapiServer.route([
  {
    method : "GET",
    path : "/admin/users",
    handler : UsersController.index
  },
  {
    method : "GET",
    path : "/admin/users/{id}",
    handler : UsersController.show
  },
  ...
]);

About

This is a resource function created for hapi.js in order to in order to reduce the amount of boilerplate code when writing hapi routes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published