typescript-boot
TypeScript icon, indicating that this package has built-in type declarations

1.0.33 • Public • Published

typescript-boot

这是一个可以帮助你用typescript快速开发后端API接口服务的脚手架。同时支持通过注解生成完全可供前端同学开发参考的在线接口文档。

里面提供了包括session会话管理、权限管理、日志管理的开箱即用功能,同时又支持完全自定义这些管理器。

还提供了方便操作数据库的方式,支持各种数据库(支持mysql、达梦数据库、其他数据库也很方便可以实现)。对数据库的操作支持对象映射。

以下是一个简单示例:

更多功能可以参考这个完整的、可运行的示例:https://github.com/seeksdream/typescript-boot-demo

1,首先安装依赖

npm install typescript-boot

2,编写代码

// 首先,编写一个接口服务:

@apiDoc('权限认证') // 描述服务名称
@apiPermission(NoRequiredPermission) // 设置访问当前接口服务的前置条件,如无需登录、需要登录、仅限指定角色登录等
@apiPath('/account') //设置访问此服务下的接口的前缀路径
export default class AccountService extends BaseService{
  @apiDoc('登录')
  @apiReturn('会话token(string)') // 描述返回结果中数据内容
  @apiPath('login') //结合服务路径/account,最终此接口的访问路径为:http://localhost:端口/account/login
  async login(
    @apiParamFromBody('登录账号') account:string, // 从body中获取account属性,并描述account的含义为:登录账号
    @apiParamFromBody('登录密码(MD5)') password:string, // 从body中获取password属性,并描述password的含义为:登录密码
    @apiRequest() req
  ) {
    // TODO 实现接口内容
    const token = '';
    return this.success(token);
  }
}

// 然后,在你的主程序中通过以下代码发布接口服务并启动

import 'reflect-metadata';
import {SeeksWebServer} from 'typescript-boot';
const port = 3333;
const server = new SeeksWebServer(port);
server.publishService(new AccountService()); // 注册一个api服务
server.start(); // 启动服务,然后就可以调用接口了

此刻,你的接口就可以被调用了。

同时,你还可以同通过以下链接来查看接口文档:

http://localhost:端口/typescript-boot

简单示例效果图

Readme

Keywords

none

Package Sidebar

Install

npm i typescript-boot

Weekly Downloads

3

Version

1.0.33

License

none

Unpacked Size

2.85 MB

Total Files

83

Last publish

Collaborators

  • seeksdream