Automated Action ac56a7b6e5 Create comprehensive FastAPI REST API service
- Set up FastAPI application with SQLite database
- Implement User and Item models with relationships
- Add CRUD operations for users and items
- Configure Alembic for database migrations
- Include API documentation at /docs and /redoc
- Add health check endpoint at /health
- Enable CORS for all origins
- Structure code with proper separation of concerns
2025-06-25 11:20:01 +00:00

47 lines
1.1 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.api_v1.api import api_router
from app.db.session import engine
from app.db.base import Base
# Create database tables
Base.metadata.create_all(bind=engine)
app = FastAPI(
title="REST API Service",
description="A comprehensive REST API built with FastAPI",
version="1.0.0",
openapi_url="/openapi.json",
docs_url="/docs",
redoc_url="/redoc"
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API routes
app.include_router(api_router, prefix="/api/v1")
@app.get("/")
async def root():
return {
"title": "REST API Service",
"description": "A comprehensive REST API built with FastAPI",
"documentation": "/docs",
"health_check": "/health"
}
@app.get("/health")
async def health_check():
return {
"status": "healthy",
"service": "REST API Service",
"version": "1.0.0"
}