fastapi-router-py
microsoft/skills
정립된 패턴에 따라 CRUD 작업, 인증 종속성 및 적절한 응답 모델을 갖춘 FastAPI 라우터를 생성합니다.
...모든 것을 확장하십시오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)
통합 단계
- 다음 위치에 라우터 생성
src/backend/app/routers/ - 마운트
src/backend/app/main.py - 해당 Pydantic 모델 생성
- 필요한 경우 서비스 계층 생성
- 프론트엔드 API 함수 추가
모범 사례
- 비동기 I/O를 호출하는지 여부에 따라 엔드포인트별로
def또는async def를 선택하십시오. 하나의 핸들러에서 동기 및 비동기 차단 호출을 혼합하지 마십시오. lifespan에서 장기적으로 유지되는 리소스(DB 풀, HTTP 클라이언트)를 관리하고Depends를 통해 주입하십시오. 요청별 리소스의 경우with/async with을 사용하여 요청별 리소스를 관리하십시오.
---
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
복사





집
