# router **Repository Path**: typified-web/router ## Basic Information - **Project Name**: router - **Description**: 创建一个类型安全、一致的 HTTP 路由! - **Primary Language**: Unknown - **License**: ISC - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-08 - **Last Updated**: 2021-10-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @typified-web/router A type-safe wrapper over koa router with focus on maintenance and consistence. ## Getting Started To install the package via npm: ```sh npm i @typified-web/router ``` To define a router: ```ts import { defineRouter } from '@typified-web/router'; const router = defineRouter((define) => ({ routes: [ define.route({ method: 'GET', input: define.input((types) => ({ body: types.string() })), output: define.output((types) => ({ body: types.string() })), }})((ctx) => { return { status: 200, header: {}, body: ctx.body, }; }), ] })); ``` Add it to server and run. ```ts import Koa from 'koa'; import { defineMiddleware } from '@typified-web/router'; const app = new Koa(); app.use(defineMiddleware(router)); app.listen(3000); ``` To export the OpenAPI document: ```ts import { exportOpenAPI } from '@typified-web/router'; const doc = exportOpenAPI(router); ``` ## License ISC