@brandondunc/typescript-rest

中文文档
3.0.7发布于 2024/11/09MITTypeScriptCommonJS近 30 天下载 1.1万

创建带有 Typescript 的 RESTFul API 的库, 从 typescript- resst 创建

中文使用文档
文档目录7 节
  1. 前言
  2. 安装
  3. 配置
  4. 基本用途
  5. 使用IoC容器
  6. 完整指南
  7. 布尔普拉特项目

npm version Master Workflow Coverage Status Known Vulnerabilities

REST 字体服务

这是轻量级的注解 表达式 用于打字的扩展名.

它可用于使用装饰器定义您的 API .

目录

前言

此寄存器于2022年8月被叉开,以解决自上次正式打字后对仍在使用库的人的紧急安全更新.

安装

这个库只用打字机工作. 确保安装:

npm install typescript -g

要安装打字机后退 :

npm install typescript-rest --save

配置

Typescript-rest 在您的 tsconfig.json 文件中需要以下 TypeScript 编译选项 :

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es6" // or anything newer like esnext
  }
}

基本用途

import * as express from "express";
import {Server, Path, GET, PathParam} from "typescript-rest";

@Path("/hello")
class HelloService {
  @Path(":name")
  @GET
  sayHello( @PathParam('name') name: string ): string {
    return "Hello " + name;
  }
}

let app: express.Application = express();
Server.buildServices(app);

app.listen(3000, function() {
  console.log('Rest Server listening on port 3000!');
});

就是这样。 你可以现在就打电话:

GET http://localhost:3000/hello/joe

使用IoC容器

为IoC集装箱安装IoC集装箱和服务Factory

npm install typescript-rest --save
npm install typescript-ioc --save
npm install typescript-rest-ioc --save

然后在您的工程根中添加一个休止. config 文件 :

{
  "serviceFactory": "typescript-rest-ioc"
}

你可以使用注射器,请求瞄准镜和IoC容器的所有特性. 它可以与任何其他IoC容器一起使用,如倒置.

示例

class HelloService {
  sayHello(name: string) {
    return "Hello " + name;
  }
}

@Path("/hello")
class HelloRestService {
  @Inject
  private helloService: HelloService;

  @Path(":name")
  @GET
  sayHello( @PathParam('name') name: string): string {
    return this.sayHello(name);
  }
}

完整指南

检查我们 文档。 。 。 .

布尔普拉特项目

你可以检查 这个项目 要开始.

版本与发布记录

@brandondunc/typescript-rest 共发布 3 个版本,首次发布于 2022/08/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.7latest2024/11/092 年前
3.0.62023/07/183 年前
3.0.52022/08/274 年前

关于 @brandondunc/typescript-rest 的常见问题

@brandondunc/typescript-rest 是什么?

创建带有 Typescript 的 RESTFul API 的库, 从 typescript- resst 创建

如何安装 @brandondunc/typescript-rest?

在项目目录运行 npm install @brandondunc/typescript-rest,或使用 pnpm add / yarn add / bun add。

@brandondunc/typescript-rest 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brandondunc/typescript-rest 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@brandondunc/typescript-rest 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@brandondunc/typescript-rest 可以商用吗?

@brandondunc/typescript-rest 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brandondunc/typescript-rest 的下载量有多少?

根据 npm 官方下载统计,@brandondunc/typescript-rest 在 2026/10/09 – 2026/11/07 这 30 天内被下载 10,713 次,日均约 357 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brandondunc/typescript-rest 还在维护吗?

最新版本 3.0.7 发布于 2024/11/09(2 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/08/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。