Socket
Socket
Sign inDemoInstall

typescript-boot

Package Overview
Dependencies
352
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typescript-boot

typescript-boot, This is a scaffolding that allows you to quickly start developing api interface services using typescript


Version published
Weekly downloads
3
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

简单示例效果图

FAQs

Last updated on 19 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc