A effortlessly express package to generate resourceful routes
npm install resourceful-routesA effortlessly express package to generate resourceful routes
``bash`
npm install resourceful-routes`
orbash`
yarn add resourceful-routes
Import the package and pass your express router object as a param.
Example:
`javascript
// routes.js
const router = require('express').Router();
require('resourceful-routes')(router, { debug: true });
router.resource('/users', UsersController, {
except: ['show', 'destroy']
});
router.resource('contacts', ContactsController, {
only: ['show'],
paramName: 'contact_id'
})
`
Will mount the following routes:
| Route | Method |
|--|--|
| /users | get |/users
| | post |/users/:id
| | put and patch |/contacts/:contact_id
| | get |
The initial setup for the package
| Param | Description |
| -- | -- |
| router | The express router object |options
| | constructor options object
| Option | Type | Description |
| -- | -- | -- |
| debug | Boolean | If set to true the /route/info route will be created to list all your available routes |
Mount all the following routes, if not specified different in options
| Route | Method |
|--|--|
| /path | get |/path
| | post |/path/:id
| | get |/path/:id
| | put patch |/path/:id
| | destroy |
| Param | Type | Description |
| -- | -- | -- |
| path | string | The path name to be mounted |controller
| | object | The object containing the functions |options
| | object | The options object
`javascript`
{
only: [],
except: [],
paramName: ':id'
}
| Option | Type | Default | Description |
| -- | -- | -- | -- |
| only | Array | [] | An array containg the actions that should be mounted |except
| | Array | [] | An array containg the actions that should not be mounted |paramName
| | string | :id` | The route param name |