eli-router-koa

1.0.0 • Public • Published

eli-router-koa

Handy router eli-router as koa middleware.

Installation

$ npm install eli-router-koa --save

Usage

const Router = require('eli-router-koa')

let router = new Router()


// Add single route with URL param, :: stand for param.
router.route('/user/::', function *(next, id) {
    this.body = `User's id is ${id}`
    yield* next
})

// Nested routes
let admin_router = router.route('/admin', function *(next) {
    let hasLogin = yield this.checkSession() // Check session somehow

    if (hasLogin) {
        yield next
    } else {
        this.redirect(url_to_login)
    }
})

admin_router.route('/::', function *(next, method) {
    this.body = `Admin's ${method} operating`
})

More useage and APIs see eli-router

TODO

  • .get() .post() put() .delete() methods

  • URL constructor like flask's url_for()

  • Whatever awesome

Readme

Keywords

none

Package Sidebar

Install

npm i eli-router-koa

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • hcyue