Hapi extension to generate restful routes. It is inspired by the module hapi-resource of Sako Hartounian https://github.com/sakoh/hapi-resource
$ npm install --save hapi-rest-routes
Given the fact that you have a restful resource controller for your blog posts with a index
and show
function.
var PostController = {
index: function(request, reply) {
...
},
show: function(request, reply) {
...
}
};
To generate the routes for your controller, you just have to use the hapit-rest-routes package.
var hapiRestRoutes = require('hapi-rest-routes');
var PostController = require('./PostController');
var restRoutes = hapiRestRoutes({
name: 'post',
namespace: 'blog',
controller: PostController,
methods: ['index', 'show']
});
This will generate the following routes.
[
{
method: "GET",
path: "/blog/posts",
controller: PostController.index,
config: {
id: "blog.posts.index"
}
},
{
method: "GET",
path: "/blog/posts/{id)",
controller: PostController.show,
config: {
id: "blog.posts.show"
}
}
]
Type: String
Name of the resource.
Type: String
Default Value: options.name + 's'
If you have a resource that needs a specific plural name for the url and route id, you're able to specify this name with this attribute. The default value will be generated by the letter s added to the name attribute.
Type: Object
Your Controller object including all controller functions you need.
Type: String
Structure your resources within namespaces to support multiple resources with the same name. In example you're able to add a post controller for blog posts and board posts by specifying a blog
and board
namespace.
Type: Array
Default Value: ['index', 'show', 'create', 'store', 'edit', 'update', 'destroy']
Limit the restful functions you want to support for your resource. If this attribute isn't set all restful functions will be supported.
Type: String
Regular expression to limit the value of the id parameter to match this expression.
GNU General Public License v2.0 © Dominic Bäuerle