0.1.0 • Published 7 years ago

night-route v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

night-route

NPM Version Build Status Node.js Version

fast routing without regexp

using with koa

const { Router } = require('night-route/koa')

let router = new Router()
router.get('/size/:width/:height', ctx => {
    ctx.body = ctx.params.width * ctx.params.height
})

app.use(router.routes())

in batch

router.route('/posts', {
  get (ctx) {}
  post (ctx) {}
})

router.route('/posts/:id', middleware, middleware2, {
  get (ctx) {},
  put (ctx) {},
  delete (ctx) {}
})

shorthands

const { GET } = require('night-route/koa')

app.use(GET('/', ctx => {
  ctx.body = "index"
}))

more http methods

router.route('TRACE', ctx => {})