@typified-web/router

0.0.3 • Public • Published

@typified-web/router

A type-safe wrapper over koa router with focus on maintenance and consistence.

Getting Started

To install the package via npm:

npm i @typified-web/router

To define a router:

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.

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:

import { exportOpenAPI } from '@typified-web/router';

const doc = exportOpenAPI(router);

License

ISC

Readme

Keywords

Package Sidebar

Install

npm i @typified-web/router

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

42.2 kB

Total Files

6

Last publish

Collaborators

  • yfwz100