跳到正文
Skillpedia
API 与服务器(后端)48k · #4599

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fastapi-router-py/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  1. Create router in src/backend/app/routers/
  2. Mount in src/backend/app/main.py
  3. Create corresponding Pydantic models
  4. Create service layer if needed
  5. 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.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4599
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能