2.1.1 • Published 2 months ago

fire-cat v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

koa-based upper frame encapsulation

version license npm

Language

English Doc 中文文档

Features

  • Use decorators
  • Custom interceptor
  • Simple to use
  • Pleasant development experience

Installation

Using npm:

npm i fire-cat

Using yarn:

yarn add fire-cat

Use project templates

git clone https://github.com/Jon-Millent/fire-cat-started.git
cd fire-cat-started
yarn

Usage

Create controller

controller.ts

import {ApiDescription, FireCatController, Get, Request, Context} from "fire-cat";

export class HomeController extends FireCatController {

  @Get('/')
  @Request()
  @ApiDescription('index page')
  index(ctx: Context) {
    ctx.body = 'hello world'
  }

  @Get('/ping')
  @Request()
  @ApiDescription('ping page')
  ping(ctx: Context) {
    ctx.body = 'pang'
  }

}

Custom interceptor

import {FireCatDecorator} from "fire-cat";

export const AuthLogin = function () {
  return FireCatDecorator.registerImplement((ctx, next) => {
    ctx.state.userInfo = {
      id: 1,
      name: 'fake',
      some: 'bar'
    }
    next()
  })
}

Use interceptors

class MyController extends FireCatController {
  @Post('hello')
  @AuthLogin()
  hello(ctx: Context) {
    console.log(ctx.state.userInfo)
    ctx.body = "hello world"
  }
}

Bind route

router.ts

import {FireCatRouter} from "fire-cat";
import {HomeController} from "controller.ts";

const fireRouter = new FireCatRouter()

fireRouter.controller('/', new HomeController())

export default fireRouter

Start your application

app.ts

import {FireCat} from "fire-cat";
import {fireCatRouter} from "router.ts";

const app = new FireCat();

app.koa.use(fireCatRouter.router.routes());
app.koa.listen('3010');

console.log(
  `🐳️app is running at http://127.0.0.1:3010`,
);

Document

English Doc 中文文档

license

MIT

2.1.1

2 months ago

2.0.9

8 months ago

2.0.10

8 months ago

2.0.8

8 months ago

2.1.0

7 months ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago