Skip to content

Commit a26dc02

Browse files
committed
update docs
1 parent 8cbb06d commit a26dc02

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const mySidebar: ThemeSidebarMulti = {
3636
{ text: '分页', link: 'pagination' },
3737
{ text: '接口响应', link: 'response' },
3838
{ text: '自定义异常', link: '/planet', icon: 'fluent-color:receipt-16' },
39+
{ text: '节流', link: 'limit' },
3940
{ text: '切换数据库', link: 'db' },
4041
{ text: 'JWT', link: 'jwt' },
4142
{ text: 'RBAC', link: 'RBAC' },

docs/backend/reference/limit.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: 节流
3+
---
4+
5+
fba 内部使用 [fastapi-limit](https://github.com/fastapi-practices/fastapi_best_architecture/discussions/70)
6+
实现后端接口节流
7+
8+
使用方法如下:
9+
10+
```python{1,6,11-17,25,29}
11+
@app.get("/", dependencies=[Depends(RateLimiter(times=2, seconds=5))])
12+
async def index_get():
13+
return {"msg": "Hello World"}
14+
15+
16+
@app.post("/", dependencies=[Depends(RateLimiter(times=1, seconds=5))])
17+
async def index_post():
18+
return {"msg": "Hello World"}
19+
20+
21+
@app.get(
22+
"/multiple",
23+
dependencies=[
24+
Depends(RateLimiter(times=1, seconds=5)),
25+
Depends(RateLimiter(times=2, seconds=15)),
26+
],
27+
)
28+
async def multiple():
29+
return {"msg": "Hello World"}
30+
31+
32+
@app.websocket("/ws")
33+
async def websocket_endpoint(websocket: WebSocket):
34+
await websocket.accept()
35+
ratelimit = WebSocketRateLimiter(times=1, seconds=5)
36+
while True:
37+
try:
38+
data = await websocket.receive_text()
39+
await ratelimit(websocket, context_key=data)
40+
await websocket.send_text("Hello, world")
41+
except HTTPException:
42+
await websocket.send_text("Hello again")
43+
```
44+
45+
更多使用方法请查看官方仓库 [示例](https://github.com/long2ice/fastapi-limiter/blob/master/examples/main.py)
46+
[源码](https://github.com/long2ice/fastapi-limiter/blob/master/fastapi_limiter/depends.py)

docs/backend/reference/pagination.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
title: 分页
33
---
44

5-
需等待 PR
5+
后期将发生改变,需等待 PR
66
合并:[Allow to have multiple Query parameter models](https://github.com/fastapi/fastapi/pull/12944#pullrequestreview-2588580175)

docs/frontend/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ title: 快速开始
55
奋力开发中...
66

77
::: warning
8-
抢险拉取代码进行体验的用户,请同步拉取最新 fba 代码并清理 redis 缓存
8+
抢先拉取代码进行体验的用户,请同步拉取最新 fba 代码并清理 redis 缓存
99
:::

0 commit comments

Comments
 (0)