# Build Reliable FastAPI API Patterns

FastAPI projects often drift into inconsistent routes, responses, and schemas. This skill gives practical patterns for endpoints, validation, errors, middleware, and OpenAPI.

## Install

```bash
npx skillstore add cjharmath/py-fastapi-patterns
```

## Metadata

- Status: approved
- Slug: cjharmath-py-fastapi-patterns
- Skillstore revision: r1
- Version status: missing
- Tree hash: 5393fcfb568e0de6e0b9d892deba71a2de13a2984326cd9c638425260e5f8ff8
- Author: CJHarmath
- GitHub username: CJHarmath
- License: MIT
- Repository: https://github.com/CJHarmath/claude-agents-skills/tree/main/skills/py-fastapi-patterns
- Ref: dd4a3ef9f20ddf38830950b4bb713df96b431fd6
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/cjharmath-py-fastapi-patterns
- Manifest: https://skillstore.pages.dev/api/skills/cjharmath-py-fastapi-patterns/manifest

## Capabilities

- Shows dependency injection patterns for sessions, authentication, and active-user checks.
- Explains response\_model usage for single objects, lists, and paginated responses.
- Provides error handling examples with HTTP status codes and custom exceptions.
- Covers route ordering, path parameters, query parameters, and enum validation.
- Demonstrates middleware setup for CORS and request timing.
- Guides OpenAPI documentation and router organization for frontend code generation.

## Use Cases

- Design New API Endpoints: Create endpoints with clean dependencies, response models, validation, and predictable status codes.
- Improve Frontend Code Generation: Clean OpenAPI schemas so generated clients expose stable types and useful endpoint metadata.
- Review FastAPI Pull Requests: Check route ordering, response filtering, middleware placement, and common integration issues.

## Prompt Templates

### Create a Basic Endpoint

```
Use this skill to design a FastAPI endpoint for [resource]. Include dependencies, request validation, response_model, and expected status codes.
```

### Fix Response Models

```
Review my FastAPI routes for missing or weak response_model usage. Explain what fields may leak and suggest safer response schemas.
```

### Audit Route Behavior

```
Analyze these FastAPI routes for route ordering problems, path parameter issues, query validation gaps, and inconsistent error responses.
```

### Prepare OpenAPI for Clients

```
Use this skill to refine my OpenAPI schema for frontend code generation. Focus on descriptions, examples, pagination, errors, and router organization.
```

## Limitations

- It provides patterns and examples, not a complete runnable FastAPI application.
- It does not implement token verification, database sessions, or production authentication.
- Examples assume familiarity with FastAPI, Pydantic, SQLModel, and async Python.
- Detection commands require a local project and user approval before execution.

## Best Practices

- Define response models on public routes to prevent accidental field exposure.
- Place specific routes before parameterized routes so FastAPI matches the intended endpoint.
- Keep OpenAPI descriptions, examples, and error responses accurate for generated clients.

## Anti Patterns

- Returning ORM models directly from public endpoints without a filtered response schema.
- Using broad string path parameters when a constrained type or enum would be safer.
- Treating generated OpenAPI output as an afterthought after frontend integration breaks.

## Security Audit

- Audited at: 2026-07-06T06:37:59.598\+00:00
- Summary: All static command-execution hits are Markdown fences, inline code, or optional local detection commands in SKILL.md rather than executable skill logic. The network and system-reconnaissance hits are documentation URLs, localhost examples, or normal API samples; no prompt injection or malicious intent was found.

## Stats

- Views: 238
- Downloads: 8
- Favorites: 0
- Popularity score: 0
