npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ainative/skill-api-design

v1.0.0

Published

FastAPI best practices, Pydantic models, RESTful endpoint design, error handling, and authentication patterns. Use when designing APIs, creating endpoints, or implementing backend logic.

Readme

API Design Skill

Expert FastAPI backend architect specializing in RESTful API design, Pydantic data validation, and scalable backend systems.

Installation

npm install @ainative/skill-api-design

Usage

Activate this skill when:

  • Designing new REST APIs or endpoints
  • Creating Pydantic models and schemas
  • Implementing authentication (JWT, OAuth)
  • Setting up error handling and validation
  • Structuring FastAPI applications
  • Working with OpenAPI/Swagger documentation

What's Included

Core Skill File

  • SKILL.md - Complete FastAPI and Pydantic expertise

Reference Documentation

1. Endpoint Patterns (references/endpoint-patterns.md)

  • Complete CRUD implementation examples
  • List endpoints with pagination and filtering
  • Nested resource patterns
  • Bulk operations
  • Search and filtering
  • Custom actions (publish, archive, etc.)

2. Pydantic Models (references/pydantic-models.md)

  • Base model architecture (Create, Update, Response)
  • Advanced validation patterns
  • Nested models and relationships
  • Dynamic models with field validation
  • Model inheritance patterns
  • Computed fields and properties

3. Error Handling (references/error-handling.md)

  • Standard error response models
  • Custom exception classes (ValidationError, NotFoundError, etc.)
  • Global exception handlers
  • Database error handling with retries
  • Validation helper functions

4. Authentication Patterns (references/auth-patterns.md)

  • Complete JWT authentication implementation
  • Password hashing with bcrypt
  • Token creation and verification
  • Protected endpoint dependencies
  • API key authentication
  • Role-based access control (RBAC)
  • OAuth2 password flow

Quick Examples

Complete API Endpoint

from fastapi import APIRouter, HTTPException, Depends

router = APIRouter(prefix="/api/v1/users", tags=["users"])

@router.post("/", status_code=201, response_model=UserResponse)
async def create_user(
    user: UserCreate,
    current_user=Depends(get_current_admin)
):
    """Create a new user (admin only)"""
    if await user_exists(user.email):
        raise HTTPException(status_code=400, detail="Email already registered")

    hashed_password = hash_password(user.password)
    new_user = await create_user_db(user, hashed_password)
    return new_user

Pydantic Model with Validation

from pydantic import BaseModel, Field, validator

class UserCreate(BaseModel):
    email: str = Field(..., pattern=r"^[\w\.-]+@[\w\.-]+\.\w+$")
    password: str = Field(..., min_length=8)
    age: int = Field(..., ge=13, le=120)

    @validator('password')
    def password_strength(cls, v):
        if not any(c.isupper() for c in v):
            raise ValueError('Password must contain uppercase letter')
        if not any(c.isdigit() for c in v):
            raise ValueError('Password must contain a digit')
        return v

JWT Authentication

from fastapi import Depends
from fastapi.security import HTTPBearer

security = HTTPBearer()

async def get_current_user(credentials=Depends(security)):
    token = credentials.credentials
    payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
    user_id = payload.get("sub")
    return await find_user(user_id)

@router.get("/me", response_model=UserResponse)
async def get_profile(current_user=Depends(get_current_user)):
    return current_user

Key Principles

  1. RESTful Design - Semantic HTTP methods, resource-oriented URLs
  2. Pydantic First - Define schemas before endpoints
  3. Security by Default - Always validate input, use dependency injection
  4. Developer Experience - Clear structure, comprehensive docs

Best Practices

  • Use Field() for validation and documentation
  • Separate Create/Update/Response models
  • Return appropriate HTTP status codes
  • Implement comprehensive error handling
  • Use dependency injection for auth and database
  • Document with docstrings (becomes OpenAPI docs)
  • Version your API (/api/v1/)
  • Use async/await for I/O operations

Requirements

fastapi>=0.104.0
pydantic>=2.0.0
python-jose[cryptography]>=3.3.0
passlib[bcrypt]>=1.7.4
python-multipart>=0.0.6

OpenAPI Integration

All examples automatically generate:

  • Interactive Swagger UI at /docs
  • ReDoc documentation at /redoc
  • OpenAPI schema at /openapi.json

Testing Examples

from fastapi.testclient import TestClient

client = TestClient(app)

def test_create_user():
    response = client.post("/api/v1/users", json={
        "email": "[email protected]",
        "password": "SecurePass123!",
        "age": 25
    })
    assert response.status_code == 201
    assert response.json()["email"] == "[email protected]"

License

MIT

Support

For issues and questions, please visit the GitHub repository.