0.0.17 • Published 3 years ago
@tofurama3000/tree-router v0.0.17
Tree Router
Basic router based off of a tree datastructure.
Basic usage with Koa:
const Koa = require('koa')
const koaBody = require('koa-body')
const router = require('./router/koa')
const app = new Koa()
const routes = router([
[
'/add',
{
get: {
parameters: { query: ['x', 'y'] },
handler: ({ query: { x, y } }) => +x + +y
},
post: {
handler: ({ body: { x, y } }) => +x + y,
middleware: [
(ctx, nxt) => {
console.log(ctx.request.body)
return nxt()
}
]
},
middleware: [koaBody()]
},
[
'/:x/:y',
{
any: {
handler: ({
pathParams: { x, y },
query: { z = 0 },
body: { q = 0 }
}) => +x + +y + +z + +q
}
}
]
],
['/', 'hello']
])
app.use(routes)
app.listen(8080)
0.0.15
3 years ago
0.0.16
3 years ago
0.0.17
3 years ago
0.0.14
4 years ago
0.0.13
4 years ago
0.0.11-pre
4 years ago
0.0.11
4 years ago
0.0.12
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago