1.0.18 • Published 5 years ago
tidy-router v1.0.18
tidy-router
tidy router used tidy-path-tree
Installation
$ npm install tidy-router --save
Usage
// for typescript
import { tidyBodyParser, tidyServerApp } from 'tidyjs'
import { tidyRouter } from 'tidy-router'
import { tjs } from 'tidy-json-schema'
const router = tidyRouter<any>()
.on('GET', '/test/:name/:value', ctx => {
return {
req: ctx.req
}
})
.on({
req: tjs.obj({
params: tjs.obj({
ver: tjs.str(),
count: tjs.int().max(100),
})
})
},
'GET', '/test2/:ver/:count', ctx => {
return {
req: ctx.req
}
})
.on<{
req: {
body: {
a: string,
b?: number
}
}
resp: {
body: {
c: string
}
}
}>('POST', '/test3', ctx => {
return {
c: ctx.req.body.a + ctx.req.body.b || '0'
}
})
tidyServerApp()
.use(tidyBodyParser())
.use(router)
.listen(3000)