# @brandondunc/typescript-rest 中文文档

规范地址：https://npmcn.com/package/%40brandondunc/typescript-rest/

版本：3\.0\.7
npm 元数据更新时间：2024-11-08T22:59:19.347Z
中文译文更新时间：2026-11-08T14:03:24.269Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40brandondunc/typescript-rest
原文对照：https://npmcn.com/package/%40brandondunc/typescript-rest/?lang=original
项目主页：https://github.com/brandonduncan/typescript-rest#readme
源码仓库：https://github.com/brandonduncan/typescript-rest

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：970 kB，85 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=6\.0\.0
- 运行依赖：12 个
- 首次发布：2022-08-26T19:20:42.742Z
- 最新版本发布：2024-11-08T22:59:19.135Z
- 近 30 天下载量：10713（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @brandondunc/typescript-rest
```

也可以使用：`pnpm add @brandondunc/typescript-rest`、`yarn add @brandondunc/typescript-rest`、`bun add @brandondunc/typescript-rest`

## README

[![npm version](https://badge.fury.io/js/@brandondunc%2Ftypescript-rest.svg)](https://badge.fury.io/js/@brandondunc%2Ftypescript-rest.svg) ![Master Workflow](https://github.com/brandonduncan/typescript-rest/workflows/Master%20Workflow/badge.svg) [![Coverage Status](https://codecov.io/gh/brandonduncan/typescript-rest/branch/master/graph/badge.svg)](https://codecov.io/gh/brandonduncan/typescript-rest) [![Known Vulnerabilities](https://snyk.io/test/github/brandonduncan/typescript-rest/badge.svg?targetFile=package.json)](https://snyk.io/test/github/brandonduncan/typescript-rest?targetFile=package.json)

# REST 字体服务

这是轻量级的注解 [表达式](http://expressjs.com/) 用于打字的扩展名.

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

**目录**

-   [REST 字体服务](https://npmcn.com/package/%40brandondunc/typescript-rest/#)
    -   [前言](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-preface)
    -   [安装](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-installation)
    -   [配置](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-configuration)
    -   [基本用途](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-basic-usage)
    -   [使用IoC容器](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-using-with-an-ioc-container)
    -   [文档](https://github.com/thiagobustamante/typescript-rest/wiki)
    -   [布尔普拉特项目](https://npmcn.com/package/%40brandondunc/typescript-rest/#readme-boilerplate-project)

## 前言

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

## 安装

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

```bash
npm install typescript -g
```

要安装打字机后退 :

```bash
npm install typescript-rest --save
```

## 配置

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

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

## 基本用途

```typescript
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

```bash
npm install typescript-rest --save
npm install typescript-ioc --save
npm install typescript-rest-ioc --save
```

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

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

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

示例

```typescript
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);
  }
}
```

## 完整指南

检查我们 [文档](https://github.com/thiagobustamante/typescript-rest/wiki)。 。 。 .

## 布尔普拉特项目

你可以检查 [这个项目](https://github.com/vrudikov/typescript-rest-boilerplate) 要开始.

## 常见问题

### @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 和提交记录判断。

