
- Set up FastAPI project structure with SQLite and SQLAlchemy - Create models for users, books, authors, categories, and orders - Implement JWT authentication and authorization - Add CRUD endpoints for all resources - Set up Alembic for database migrations - Add health check endpoint - Add proper error handling and validation - Create comprehensive documentation
33 lines
939 B
Python
33 lines
939 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
# Import routers
|
|
from app.api.routes import books, users, orders, health
|
|
|
|
# Create FastAPI app
|
|
app = FastAPI(
|
|
title="Online Bookstore API",
|
|
description="API for an online bookstore to manage books, users, and orders",
|
|
version="1.0.0",
|
|
)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # In production, replace with specific origins
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(health.router, tags=["health"])
|
|
app.include_router(books.router, prefix="/api/books", tags=["books"])
|
|
app.include_router(users.router, prefix="/api/users", tags=["users"])
|
|
app.include_router(orders.router, prefix="/api/orders", tags=["orders"])
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|