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);
}
}
完整指南
检查我们 文档。 。 。 .
布尔普拉特项目
你可以检查 这个项目 要开始.