Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zweifisch/night-route
fast routing without regexp
https://github.com/zweifisch/night-route
koa router
Last synced: 18 days 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-20T13:34:52.000Z (almost 8 years ago)
- Last Synced: 2024-12-26T09:26:56.844Z (about 1 month 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/