https://github.com/zweifisch/night-route
fast routing without regexp
https://github.com/zweifisch/night-route
koa router
Last synced: 2 months ago
JSON representation
fast routing without regexp
- Host: GitHub
- URL: https://github.com/zweifisch/night-route
- Owner: zweifisch
- Created: 2017-04-16T13:40:25.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-20T13:34:52.000Z (about 9 years ago)
- Last Synced: 2025-02-19T22:03:31.920Z (over 1 year ago)
- Topics: koa, router
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# night-route
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Node.js Version][node-version-image]][node-version-url]
fast routing without regexp
## using with koa
```js
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
```js
router.route('/posts', {
get (ctx) {}
post (ctx) {}
})
router.route('/posts/:id', middleware, middleware2, {
get (ctx) {},
put (ctx) {},
delete (ctx) {}
})
```
### shorthands
```js
const { GET } = require('night-route/koa')
app.use(GET('/', ctx => {
ctx.body = "index"
}))
```
### more http methods
```js
router.route('TRACE', ctx => {})
```
[npm-image]: https://img.shields.io/npm/v/night-route.svg?style=flat
[npm-url]: https://npmjs.org/package/night-route
[travis-image]: https://img.shields.io/travis/zweifisch/night-route.svg?style=flat
[travis-url]: https://travis-ci.org/zweifisch/night-route
[node-version-image]: https://img.shields.io/node/v/night-route.svg
[node-version-url]: https://nodejs.org/en/download/