@antelopejs/interface-api-util
请求校验并限制处理器的帮助 @antelopejs/interface-api每一次失败都变成了 HTTPResult 错误反应 .
部分 羚羊JS用于 羚羊JS 隐形物,用于您的 PostgreSQL 、 MongoDB 或 RethinkDB 数据库的开源后台.
它提供的东西
assert(condition, code, message)丢出一个HTTPResult当病情变质 并缩小其类型时,它保持.assertValidation(body, validator)运行同步验证器, 如 Zodparse然后把一个错误变成一个错误的响应,400默认.@RateLimit(limit, windowMs)在固定窗口中给每个客户端的处理器打电话并回答429更别提了.
执行情况
帮手在你的模块里运行。 他们需要一个模块提供的API接口:
| 模块 | 页:1 |
|---|---|
@antelopejs/api | 执行 @antelopejs/interface-api 财务报告和审定财务报表 @antelopejs/interface-api-util |
安装
将软件包添加到宣布路径的模块中 :
pnpm add @antelopejs/interface-api-util
然后在项目中添加 API 接口的执行 :
ajs project modules add @antelopejs/api
快开始
import {
Controller,
Get,
HTTPResult,
Parameter,
} from "@antelopejs/interface-api";
import { RateLimit, assert } from "@antelopejs/interface-api-util";
const BOOKS = new Map([["1", { title: "The Glass Meridian" }]]);
export class BookController extends Controller("/books") {
@Get(":id")
@RateLimit(100, 60_000)
async getBook(@Parameter("id") id: string) {
const book = BOOKS.get(id);
assert(book, 404, "Book not found");
return new HTTPResult(200, book);
}
}
地点 @RateLimit 直接在路由装饰器下方. 放在上面, @RateLimit 当类被定义时会抛出.
文档
兼容性
模块宣布这些对等关系:
| 软件包 | 支助 | 测试过 |
|---|---|---|
@antelopejs/interface-api | >=0.3.0 <1.0.0 | 0.2.0 |
@antelopejs/interface-core | >=0.2.4 <1.0.0 | 0.4.0 |
捐款
读取 捐款额 在你打开拉动请求之前。 当地检查为:
pnpm install
pnpm lint
pnpm test