
- Implemented FastAPI application structure - Added OpenWeatherMap API integration - Created SQLite database with SQLAlchemy - Setup Alembic for database migrations - Added health check endpoint - Created comprehensive README generated with BackendIM... (backend.im)
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.v1.api import api_router
|
|
from app.api.health import router as health_router
|
|
from app.core.config import API_V1_STR, PROJECT_NAME
|
|
from app.db.base import Base, engine
|
|
|
|
# Create database tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title=PROJECT_NAME,
|
|
description="API for retrieving weather data from OpenWeatherMap",
|
|
version="0.1.0",
|
|
)
|
|
|
|
# Set up CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(api_router, prefix=API_V1_STR)
|
|
app.include_router(health_router)
|
|
|
|
@app.get("/", tags=["root"])
|
|
def root():
|
|
"""
|
|
Root endpoint
|
|
"""
|
|
return {
|
|
"message": "Welcome to the Weather Data API",
|
|
"docs": "/docs",
|
|
"redoc": "/redoc"
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |