fastapi-router-py
它能做什么
这段代码可以帮助你创建网站或 Web 应用中处理信息的部分,确保信息井井有条且安全。它定义了数据如何接收和发送,以及谁可以访问这些数据。
适用场景
- ✓为网站构建新板块时。
- ✓添加登录或权限功能时。
- ✓整理向用户展示数据的方式时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fastapi-router-py/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“在我的应用里新建一个用户管理板块,要有安全登录功能和用户列表展示。”
每周 5 个新技能,1 分钟读完。
工作原理
它会使用模板定义数据结构和规则,确保只有经过授权的用户才能访问特定信息。它还会设置状态码,用来表示操作是否成功。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Bundled upstream support
Supporting files are included at skill-relative paths. See UPSTREAM-NOTICE.md for their pinned sources, licenses, hashes, and import changes.
FastAPI Router
Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.
Quick Start
Copy the template from assets/template.py and replace placeholders:
{{ResourceName}}→ PascalCase name (e.g.,Project){{resource_name}}→ snake_case name (e.g.,project){{resource_plural}}→ plural form (e.g.,projects)
Authentication Patterns
# Optional auth - returns None if not authenticated
current_user: Optional[User] = Depends(get_current_user)
# Required auth - raises 401 if not authenticated
current_user: User = Depends(get_current_user_required)
Response Models
@router.get("/items/{item_id}", response_model=Item)
async def get_item(item_id: str) -> Item:
...
@router.get("/items", response_model=list[Item])
async def list_items() -> list[Item]:
...
HTTP Status Codes
@router.post("/items", status_code=status.HTTP_201_CREATED)
@router.delete("/items/{id}", status_code=status.HTTP_204_NO_CONTENT)
Integration Steps
- Create router in
src/backend/app/routers/ - Mount in
src/backend/app/main.py - Create corresponding Pydantic models
- Create service layer if needed
- Add frontend API functions
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题
什么是“路由器”(router)?
它们就像大楼里的各个分区,每层楼或每个房间都有特定用途。在代码中,它们用来组织 Web 应用的不同部分。
什么是“身份认证”?
指验证用户是否为其声称身份的过程,比如用用户名和密码登录。
什么是“响应模型”?
它们像表格一样,定义了返回给用户的内容格式和数据,确保每次返回的结果都保持一致。
详情
作者的原始描述
Create FastAPI routers following established patterns with proper authentication, response models, and HTTP status codes.
热度
- GitHub 星标
- 48k
- 排名
- #4599
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。