@tdqs/koa-api
基于koa的api中间件
Last updated 2 years ago by gzq .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @tdqs/koa-api 
SYNC missed versions from official npm registry.

@tdqs/koa-api

The MIT License (MIT)

@tdqs/koa-api koa middleware.

Table of Contents

Installation
API documentation
Example

Installation

    $ npm install @tdqs/koa-api

API documentation

Getting Started

import { api, cls, koaApi } from '@tdqs/koa-api';
import * as Koa from 'koa';

const app = new Koa();

@cls()
class Test {
  @api()
  public static hello(ctx) {
    return 'hello world';
  }
}

app.use(koaApi({}, Test)).listen(8080);

//GET localhost:8080/docs       Api document
//GET localhost:8080/hello      Response 'hello world'

jsonschema & middlewares simplification

import { api, cls, IApiContext } from '../src/index';

@cls({
  name: '测试schema',
  prefix: '/schema',
})
export class Schema {
  @api({
    method: 'POST',
    middlewares: [
      async (ctx, next) => {
        const start = new Date().getTime();
        await next();
        const ms = new Date().getTime() - start;
        ctx.body = {
          ms,
          text: ctx.body,
        };
      },
    ],
    schema: {
      properties: {
        p: { type: 'string' },
        q: { type: 'number' },
      },
      required: ['p', 'q'],
      type: 'object',
    },
  })
  public static hello(ctx: IApiContext) {
    return `hello world ${JSON.stringify(ctx.data)}`;
  }
}

Example

Following example could be found inside /tests directory.

Current Tags

  • 0.3.0                                ...           latest (2 years ago)

10 Versions

  • 0.3.0                                ...           2 years ago
  • 0.2.5                                ...           2 years ago
  • 0.2.4                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |