fastapi-app
构建 FastAPI 后端应用程序
FastAPI 技能帮助开发者创建具有自动文档、验证和依赖注入的强大 Python Web API。此技能为构建生产就绪的 FastAPI 应用程序提供专家指导,包括路由处理器、CORS 配置和 Pydantic v2 模型。
Baixar o ZIP da skill
Upload no Claude
Vá em Configurações → Capacidades → Skills → Upload skill
Ative e comece a usar
Testar
A utilizar "fastapi-app". 创建一个具有学生端点的 FastAPI 应用程序
Resultado esperado:
- 生成了具有 FastAPI 初始化、CORS 配置和生命周期事件的 main.py
- 创建了具有 CRUD 端点和身份验证依赖项的 routers/students.py
- 添加了用于异步 SQLAlchemy 会话管理的 dependencies/database.py
- 在 schemas/student.py 中生成了具有验证规则的 Pydantic 模式
A utilizar "fastapi-app". 向 API 添加 JWT 身份验证
Resultado esperado:
- 创建了具有 JWT 令牌创建和验证的 dependencies/auth.py
- 实现了使用 HTTPBearer 方案的 get_current_user 依赖项
- 添加了具有 get_admin_user 依赖项的基于角色的访问控制
- 配置了用于 JWT_SECRET_KEY 的环境变量加载
Auditoria de Segurança
Baixo RiscoAll static findings are false positives. The skill provides legitimate FastAPI development guidance. Pattern detections (C2 keywords, weak crypto, command execution) are misidentifications of standard code examples and documentation URLs in the SKILL.md file.
Problemas de Baixo Risco (1)
Fatores de risco
⚡ Contém scripts (1)
📁 Acesso ao sistema de arquivos (1)
Pontuação de qualidade
O Que Você Pode Construir
后端 API 开发
为学生管理、费用跟踪或考勤系统创建新的 FastAPI 端点,具有适当的身份验证和验证。
API 安全实现
向现有 FastAPI 应用程序添加 JWT 身份验证、基于角色的访问控制和安全的 CORS 配置。
数据验证设置
定义具有字段验证、电子邮件模式和 ORM 兼容性的 Pydantic v2 模型,用于 API 请求和响应模式。
Tente Estes Prompts
创建一个具有生命周期事件、允许 localhost:3000 和 localhost:5173 的 CORS 中间件的 FastAPI 应用程序,并包含 /api/v1/auth、/api/v1/students 和 /api/v1/fees 的路由器,具有适当的标签和依赖项。
生成具有学生资源的 GET、POST、PUT 和 DELETE 端点的 APIRouter。包括使用 skip/limit 的分页、使用 Pydantic 的响应模型,以及数据库会话和当前用户身份验证的依赖注入。
创建 JWT 身份验证的依赖项,包括 create_access_token 函数、使用 HTTPBearer 的 get_current_user 依赖项,以及用于基于角色的访问控制的 get_admin_user。使用 HS256 算法和环境变量存储密钥。
为学生实体创建 Pydantic v2 模型,包括 StudentBase、StudentCreate、StudentUpdate 和 StudentResponse。包括用于名称长度的 Field 验证器、用于电子邮件的 EmailStr,以及用于 ORM 兼容性的 ConfigDict。
Melhores Práticas
- 使用带有上下文管理器的异步 SQLAlchemy 会话以防止连接泄漏
- 始终为 API 响应返回适当的 HTTP 状态码(200、201、204、400、401、403、404)
- 使用 os.getenv() 将密钥存储在环境变量中,并为开发环境设置合理的默认值
Evitar
- 不要在源代码文件中直接硬编码密钥或密码
- 不要在异步 FastAPI 路由处理器中使用同步数据库调用
- 不要禁用 Pydantic 验证或在端点中省略响应模型
Perguntas Frequentes
此技能支持哪些 FastAPI 功能?
此技能是否生成身份验证代码?
此技能可以创建数据库模型吗?
Pydantic v2 支持什么验证?
CORS 配置如何工作?
此技能是否处理部署或 Docker?
Detalhes do Desenvolvedor
Autor
Awais68Licença
MIT
Repositório
https://github.com/Awais68/hackathon-2-phase-ii-full-stack-web-app/tree/main/.claude/skills/fastapi-appReferência
main
Estrutura de arquivos
📄 SKILL.md