1.0.18 • Published 5 years ago

tidy-router v1.0.18

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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)
1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago