オプション
家 Skill 開発者ツール fastapi-router-py

fastapi-router-py

microsoft/skills microsoft/skills

確立されたパターンに従い、CRUD操作、認証の依存関係、および適切なレスポンスモデルを備えたFastAPIルーターを作成します。

...すべて拡張します
10
更新された時間 2026年9月12日

FastAPI ルーター

適切な認証、レスポンスモデル、およびHTTPステータスコードを備えた、確立されたパターンに従ったFastAPIルーターを作成します。

クイックスタート

assets/template.py からテンプレートをコピーし、プレースホルダーを置き換えます:

  • {{ResourceName}} → PascalCase形式の名前(例: Project)
  • {{resource_name}} → snake_case形式の名称(例: project)
  • {{resource_plural}} → 複数形(例: projects)

認証パターン

# 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)

レスポンスモデル

@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ステータスコード

@router.post("/items", status_code=status.HTTP_201_CREATED)
@router.delete("/items/{id}", status_code=status.HTTP_204_NO_CONTENT)

統合の手順

  1. 以下の場所にルーターを作成する src/backend/app/routers/
  2. マウント先 src/backend/app/main.py
  3. 対応するPydanticモデルを作成する
  4. 必要に応じてサービス層を作成する
  5. フロントエンドAPI関数を追加する

ベストプラクティス

  1. 非同期I/Oを呼び出すかどうかによって、エンドポイントごとに `def` または `async def` を選択してください。1つのハンドラ内で同期呼び出しと非同期のブロッキング呼び出しを混在させないでください。
  2. lifespan内で長期存続リソース(DBプール、HTTPクライアント)を管理し、Dependsを介して注入してください。リクエストごとのリソースについては with/async with を使用してください。
GitHubで見る
---
name: fastapi-router-py
description: Create FastAPI routers with CRUD operations, authentication dependencies, and proper response models following established patterns.
license: MIT
---

# 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](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

```python
# 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

```python
@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

```python
@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

## Best Practices

1. **Pick `def` or `async def` per endpoint based on whether you call async I/O;** do not mix sync and async blocking calls in one handler.
2. **Manage long-lived resources (DB pools, HTTP clients) in `lifespan` and inject via `Depends`;** use `with`/`async with` for per-request resources.

すべてのファイル

0件のファイル

fastapi-router-pyをインストール

スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。

ZIPをダウンロード

リポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。

git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/fastapi-router-py # Copy SKILL.md to your .claude/skills/ directory

コピー コピー
クイックセットアップ: スキルフォルダを .claude/skills/ にコピーしてください。 Claude が自動的にそのスキルを検出して使用します。
リポジトリ microsoft/skills

関連スキル

algorithmic-art
更新された時間 2026年8月27日
receiving-code-review
更新された時間 2026年9月3日
tech-debt-tracker
更新された時間 2026年8月29日
senior-backend
更新された時間 2026年8月30日
OR