Files
cattleTransportation/.cursor/rules/frameworks/fastapi.mdc
2025-11-04 09:38:19 +08:00

16 lines
652 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: FastAPI 高性能 Python API 的约定和最佳实践。
globs: **/*.py
alwaysApply: false
---
# FastAPI 规则
- 为所有函数参数和返回值使用类型提示
- 使用 Pydantic 模型进行请求和响应验证
- 在路径操作装饰器中使用适当的 HTTP 方法(@app.get、@app.post 等)
- 使用依赖注入实现共享逻辑,如数据库连接和身份验证
- 使用后台任务background tasks进行非阻塞操作
- 使用适当的状态码进行响应201 表示创建404 表示未找到等)
- 使用 APIRouter 按功能或资源组织路由
- 适当使用路径参数、查询参数和请求体