一键导入
fastapi-crud-endpoint
Create new FastAPI CRUD endpoints following the project's proven router patterns (auth, rate limiting, error handling, Pydantic v2 schemas).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Create new FastAPI CRUD endpoints following the project's proven router patterns (auth, rate limiting, error handling, Pydantic v2 schemas).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create new Recharts visualization components following the project's proven chart patterns (responsive, typed, dark-mode compatible).
Create Architecture Decision Records (ADRs). Use when the user wants to record an architectural decision, document a technical choice, or when creating a new ADR for a PR.
Maintain and update the project CHANGELOG.md. Use when merging PRs, preparing releases, when the user asks to update the changelog, add changelog entries, or review changelog quality.
Reference guide for advanced git workflow patterns including worktrees, parallel development, and periodic cleanup. Use when setting up worktrees, doing parallel development, or cleaning up stale branches.
Create, review, and edit Request for Comments (RFC) documents for technical proposals. Use when the user wants to write an RFC, design document, technical proposal, or feature specification. Also use when reviewing or providing feedback on existing RFCs, or when converting ideas into structured technical proposals.
| name | fastapi-crud-endpoint |
| description | Create new FastAPI CRUD endpoints following the project's proven router patterns (auth, rate limiting, error handling, Pydantic v2 schemas). |
Generate new API endpoints that match the conventions established across the 5 existing routers (auth, predict, train, models, feature_selection).
apps/api/routers/This project uses four endpoint shapes. Pick the one that fits, then follow the template in references/router-template.py.
Return a collection. No auth required (read-only).
@router.get("/", response_model=list[ItemSchema])
async def list_items() -> list[ItemSchema]:
Return a single resource. Raise 404 if missing.
@router.get("/{item_id}", response_model=ItemSchema)
async def get_item(item_id: str) -> ItemSchema:
Accept a Pydantic request body, return a Pydantic response. Requires auth + optional rate limiting.
@router.post("/", response_model=ResponseSchema)
@limiter.limit("100/minute")
async def create_item(
request: Request,
payload: RequestSchema,
settings: Settings = Depends(get_settings),
_api_key: str = Depends(verify_api_key),
) -> ResponseSchema:
Perform an action on an existing resource (e.g., /models/{id}/persist).
@router.post("/{item_id}/action", response_model=ResponseSchema)
async def perform_action(
item_id: str,
settings: Settings = Depends(get_settings),
_api_key: str = Depends(verify_api_key),
) -> ResponseSchema:
Define Pydantic schemas in shared/schemas/<domain>.py
Field() for validation and OpenAPI docsuv run pytest tests/shared/ after changesCreate the service in apps/api/services/<domain>.py
ValueError for bad input, FileNotFoundError for missing resourcesCreate the router in apps/api/routers/<domain>.py
references/router-template.py"""<Domain> endpoint router."""router = APIRouter() at module levelRegister the router in apps/api/main.py
from apps.api.routers import new_domain
app.include_router(
new_domain.router,
prefix="/new-domain",
tags=["new-domain"],
)
Add tests in tests/api/test_<domain>.py
httpx.AsyncClient with the app fixtureitem_id: str)payload: RequestSchema)request: Request (only if rate limiting is used)settings: Settings = Depends(get_settings) (if needed)_api_key: str = Depends(verify_api_key) (if write endpoint)Every POST endpoint uses this hierarchy:
try:
result = service_function(...)
return result
except FileNotFoundError:
logger.exception("Resource not found")
raise HTTPException(status_code=404, detail="Resource not found")
except ValueError:
logger.exception("Invalid input")
raise HTTPException(status_code=400, detail="Invalid configuration")
except Exception:
logger.exception("Operation failed unexpectedly")
raise HTTPException(status_code=500, detail="Internal server error")
"10/hour" or "20/hour""100/minute"logger = logging.getLogger(__name__) at module levellogger.exception() inside except blocks (auto-attaches traceback)Every endpoint needs:
Args: sectionReturns: sectionRaises: section listing HTTPException codesExample Request: / Example Response: JSON blocks (for POST endpoints)shared/schemas/apps/api/services/apps/api/main.py with prefix and tagsuv run pytest passes