Typedef
| Static Public Summary | ||
| public |
Controller object for |
since 0.9.0 |
| public |
Controller object for |
since 0.9.0 |
| public |
Configure your |
since 0.9.0 |
| public |
Configure your |
since 0.9.0 |
| Static Protected Summary | ||
| protected |
Routes object |
|
Static Public
public CrudController: object since 0.9.0 source
Controller object for crud() method RestRoutes
Properties:
| Name | Type | Attribute | Description |
| beforeEach | function |
|
Called before each request |
| afterEach | function |
|
Called after each request |
| read | function |
|
Handle GET /name |
| create | function |
|
Handle POST /name |
| update | function |
|
Handle PUT /name |
| destroy | function |
|
handle DELETE /name |
Example:
const DemoController = {
beforeEach(req, res, next) {
// any checks here
next()
},
create(req, res, next) {
context.makeDemo.create(req.params)
res.json({ complete: true })
next()
},
afterEach(req, res, next) {
// close your resources here
context.db.close()
}
}
public ResourcesController: object since 0.9.0 source
Controller object for resources() method. See Maker.resources
Properties:
| Name | Type | Attribute | Description |
| beforeEach | function |
|
Hook will invoke before each handler in controller |
| afterEach | function |
|
Hook will invoke before after handler in controller |
| index | function |
|
|
| create | function |
|
|
| read | function |
|
|
| update | function |
|
|
| patch | function |
|
|
| destroy | function |
|
public crudOptions: object since 0.9.0 source
Configure your crud('name', controller, options)
See Maker.crud
Example:
createRest(root => {
root.crud('foo', FooController, { only: ['read'] })
})
createRest(root => {
root.crud('bar', BarController, { except: ['destroy', 'update'] })
})
const Controller = {
createDemo() {},
updateMe() {},
justExample() {},
youDontNeedThis() {},
}
createRest(root => {
root.crud('demo', Controller, { methodNames: {
read: 'justExample', create: 'createDemo', update: 'updateMe', destroy: 'youDontNeedThis',
}})
})
public resourcesOptions: object since 0.9.0 source
Configure your resources('name', controller, options)
You can't use except and only at the same time
Available handlers: index, read, create, update, patch, destroy
Example:
createRest(root => {
// GET /books -> index()
// GET /books/:bookId -> read()
root.resources('books', BooksController, { only: ['read', 'index'] })
})
createRest(root => {
// GET /songs -> index()
// POST /songs -> create()
// GET /songs/:songId -> read()
// PATCH /songs/:songId -> patch()
root.resources('songs', SongsController, { except: ['destroy', 'update'] })
})
const Controller = {
beforeEach() {},
afterEach() {},
create() {},
read() {},
}
// If controller no methods, no handlers creates
createRest(root => {
// GET /demo beforeEach(); read(); afterEach()
// POST /demo beforeEach(); create(); afterEach()
root.crud('demo', Controller)
})
createRest(root => {
// GET /images -> index()
// POST /images -> create()
// GET /images/:imgid -> read()
// PUT /images/:imgid -> update()
// PATCH /images/:imgid -> patch()
// DELETE /images/:imgid -> destroy()
root.resources('images', ImagesController, { memberId: 'imgid' })
})
