koa-joi-rest

2.2.1 • Public • Published

koa-joi-rest build

koa-joi-rest is a super simple tool to build Koa.js controller like Laravel controller, use koa-joi-router

Requirement

  • node.js >= 8

Install

npm install --save koa-joi-rest

Usage

Basically, you can assign an object to get koa-router routes

const rest = require('koa-joi-rest')

const handlers = {
  index (ctx) {

  },
  store (ctx) {

  },
  // ...
}

rest(
  {
    resource: 'foo',
    handlers
  }
)

Or, you can assign nested resource like this

rest(
  {
    resource: ['foo', 'bar'],
    handlers
  }
)

The path looks like this /foo/:fooId/bar/:id

key description type
resource Route resources, it should be an array or a string. string or array
handlers An object to define CRUD like Laravel project. object
middlewares An object to define CRUD middleware like Laravel project. object
validates validation object provided by joi-router. object
prefix Add prefix to all routes string
middleware Add koa middleware to all routes function

Readme

Keywords

none

Package Sidebar

Install

npm i koa-joi-rest

Weekly Downloads

0

Version

2.2.1

License

MIT

Unpacked Size

56 kB

Total Files

9

Last publish

Collaborators

  • michael34435