# hapi-rest-routes

> Hapi extension to generate restful routes.

Latest version **1.0.0** (published 2015-10-17) · GNU General Public License v2.0 license · 0 weekly downloads

## Install

```sh
npm install hapi-rest-routes
pnpm add hapi-rest-routes
yarn add hapi-rest-routes
bun add hapi-rest-routes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-10-17 |
| First published | 2015-10-17 |
| Weekly downloads | 0 |
| License | GNU General Public License v2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dominic Baeuerle |
| Maintainers | derbaeuerle |
| Keywords | hapi restful rest routes controller |

## Links

- npm: https://www.npmjs.com/package/hapi-rest-routes
- Repository: https://github.com/derbaeuerle/hapi-rest-routes
- Homepage: https://github.com/derbaeuerle/hapi-rest-routes#readme
- Issues: https://github.com/derbaeuerle/hapi-rest-routes/issues
- npm.io page: https://npm.io/package/hapi-rest-routes

## Dependencies (1)

- [joi](https://npm.io/package/joi.md) ~6.9.1

## Recent versions

- 1.0.0 (latest) — 2015-10-17

## README

# hapi-rest-routes

> Hapi extension to generate restful routes. It is inspired by the module *hapi-resource* of Sako Hartounian [https://github.com/sakoh/hapi-resource](https://github.com/sakoh/hapi-resource)


## Install

```
$ npm install --save hapi-rest-routes
```


## Usage

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"
        }
    }
]
```


## Options

### options.name (required)
Type: `String`

Name of the resource.

### options.namePlural [optional]
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.

### options.controller (required)
Type: `Object`

Your Controller object including all controller functions you need.

### options.namespace [optional]
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.

### options.methods [optional]
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.

### options.variable [optional]
Type: `String`

Regular expression to limit the value of the id parameter to match this expression.

## License

GNU General Public License v2.0 © [Dominic Bäuerle](https://github.com/derbaeuerle)

---
_Source: https://npm.io/package/hapi-rest-routes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
