Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nameoverflow/eli-router-koa
Router for koa
https://github.com/nameoverflow/eli-router-koa
Last synced: 29 days ago
JSON representation
Router for koa
- Host: GitHub
- URL: https://github.com/nameoverflow/eli-router-koa
- Owner: nameoverflow
- Created: 2016-02-19T04:51:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-19T04:52:06.000Z (almost 9 years ago)
- Last Synced: 2024-12-04T23:33:08.426Z (30 days ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eli-router-koa
Handy router [eli-router](https://github.com/NameIsUseless/eli-router) as koa middleware.
## Installation
```shell
$ npm install eli-router-koa --save
```## Usage
```js
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 somehowif (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](https://github.com/NameIsUseless/eli-router)
## TODO
- `.get()` `.post()` `put()` `.delete()` methods
- URL constructor like flask's `url_for()`
- Whatever awesome