0.1.2 • Published 10 years ago

hapi-resource-z v0.1.2

Weekly downloads
2
License
ISC
Repository
github
Last release
10 years ago

hapi-resource

This is a resource function created for hapi.js to reduce the amount of code when writing hapi routes. this package include plural (s/ies) feature

###INSTALLATION

npm install hapi-resource-z

##USAGE

Given an API controller:

const joi             = require('joi');
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,
    validate: payload: {
      name: joi.string().alphanum().required(),
    },
    methods: ['all', 'show', 'create', 'update', 'delete' ] // optional if not defined (by default * included)
  })
);

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-z');

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
  },
  ...
]);
0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago