Home Reference Source

Typedef

Static Public Summary
public

Controller object for crud() method RestRoutes

since 0.9.0
public

Controller object for resources() method.

since 0.9.0
public

Configure your crud('name', controller, options)
See Maker.crud

since 0.9.0
public

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

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:

NameTypeAttributeDescription
beforeEach function
  • optional

Called before each request

afterEach function
  • optional

Called after each request

read function
  • optional

Handle GET /name

create function
  • optional

Handle POST /name

update function
  • optional

Handle PUT /name

destroy function
  • optional

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:

NameTypeAttributeDescription
beforeEach function
  • optional

Hook will invoke before each handler in controller

afterEach function
  • optional

Hook will invoke before after handler in controller

index function
  • optional
create function
  • optional
read function
  • optional
update function
  • optional
patch function
  • optional
destroy function
  • optional

public crudOptions: object since 0.9.0 source

Configure your crud('name', controller, options)
See Maker.crud

Properties:

NameTypeAttributeDescription
only string[]
  • optional

Keep only that handlers: read, create, update, destroy

except string[]
  • optional

Keep all except that handlers

methodNames object
  • optional

Change method names

Example:

Usage with `only`
createRest(root => {
  root.crud('foo', FooController, { only: ['read'] })
})
Usage with `except`
createRest(root => {
  root.crud('bar', BarController, { except: ['destroy', 'update'] })
})
Method names
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

Properties:

NameTypeAttributeDescription
only string[]
  • optional

Keep only that handlers

except string[]
  • optional

Keep all except that handlers

memberId string
  • optional

Change :memberId in the URI

Example:

Usage with `only`
createRest(root => {
  // GET /books          -> index()
  // GET /books/:bookId  -> read()
  root.resources('books', BooksController, { only: ['read', 'index'] })
})
Usage with `except`
createRest(root => {
  // GET /songs              -> index()
  // POST /songs             -> create()
  // GET /songs/:songId      -> read()
  // PATCH /songs/:songId    -> patch()
  root.resources('songs', SongsController, { except: ['destroy', 'update'] })
})
With beforeEach afterEach methods
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)
})
Member ID renaming
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' })
})

Static Protected

protected RestRoutes: object source

Routes object

Properties:

NameTypeAttributeDescription
Symbol(createRestInstanceSymbol) Symbol
before object[]
after object[]
scoped object
local object