# FastAPI Code Examples

Reference examples for each rule area. Read the relevant section when generating code for that area.

---

## FastAPI Rules

```python
# ✅ Good: Schema and Dependency Injection
@router.post("/", response_model=UserRead)
async def create_user(
    *,
    db: Session = Depends(get_db),
    user_in: UserCreate
):
    user = await crud.user.create(db, obj_in=user_in)
    return user
```

---

## Testing

```python
@pytest.mark.asyncio
async def test_create_user(client: AsyncClient):
    response = await client.post("/users/", json={"email": "test@example.com", "password": "password"})
    assert response.status_code == 201
```
