Skip to main content
Glama
README.md1.69 kB
# FastAPI Starter Template ## Project Structure ``` project/ ├── app/ │ ├── __init__.py │ ├── main.py # FastAPI app │ ├── config.py # Settings │ ├── dependencies.py # Shared deps │ ├── routers/ │ │ ├── __init__.py │ │ └── users.py │ ├── models/ │ │ ├── __init__.py │ │ └── user.py │ └── schemas/ │ ├── __init__.py │ └── user.py ├── tests/ │ └── test_main.py ├── requirements.txt ├── Dockerfile └── docker-compose.yml ``` ## main.py ```python from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.routers import users from app.config import settings app = FastAPI( title=settings.app_name, version="1.0.0", docs_url="/docs", redoc_url="/redoc" ) app.add_middleware( CORSMiddleware, allow_origins=settings.allowed_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(users.router, prefix="/api/v1") @app.get("/health") async def health_check(): return {"status": "healthy"} ``` ## config.py ```python from pydantic_settings import BaseSettings class Settings(BaseSettings): app_name: str = "FastAPI App" debug: bool = False database_url: str = "" allowed_origins: list[str] = ["*"] class Config: env_file = ".env" settings = Settings() ``` ## Best Practices - Use Pydantic for validation - Dependency injection with Depends() - Async for I/O operations - Proper error handling with HTTPException - Document with OpenAPI

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server