From 2e449f5437cbae4b6ebc22b3613da8fe2d188424 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Tue, 13 May 2025 05:23:42 +0000 Subject: [PATCH] Add Hello World FastAPI application with health endpoint generated with BackendIM... (backend.im) --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- main.py | 38 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/README.md b/README.md index e8acfba..2a9d0fc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,45 @@ -# FastAPI Application +# Hello World FastAPI Application -This is a FastAPI application bootstrapped by BackendIM, the AI-powered backend generation platform. +This is a simple Hello World API built with FastAPI and SQLite. + +## Features + +- Simple Hello World endpoint at `/` +- Health check endpoint at `/health` +- API documentation at `/docs` and `/redoc` +- SQLite database setup + +## Requirements + +- Python 3.8+ +- Pip for package installation + +## Installation + +1. Clone the repository +2. Install the dependencies: + +```bash +pip install -r requirements.txt +``` + +## Running the application + +Start the application using Uvicorn: + +```bash +python main.py +``` + +Or directly with Uvicorn: + +```bash +uvicorn main:app --reload +``` + +The API will be available at `http://localhost:8000` + +## API Documentation + +- Swagger UI: http://localhost:8000/docs +- ReDoc: http://localhost:8000/redoc \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..29d5f69 --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +from fastapi import FastAPI +from pathlib import Path +from sqlalchemy import create_engine +import uvicorn + +app = FastAPI( + title="Hello World API", + description="A simple FastAPI hello world application", + version="0.1.0" +) + +# Setup database +DB_DIR = Path("/app") / "storage" / "db" +DB_DIR.mkdir(parents=True, exist_ok=True) + +SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" + +engine = create_engine( + SQLALCHEMY_DATABASE_URL, + connect_args={"check_same_thread": False} +) + +@app.get("/") +def read_root(): + return {"message": "Hello World"} + +@app.get("/health", tags=["health"]) +def health_check(): + """ + Health check endpoint + """ + return { + "status": "healthy", + "api_version": app.version + } + +if __name__ == "__main__": + uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e222a4c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +fastapi>=0.103.1 +uvicorn>=0.23.2 +sqlalchemy>=2.0.20 +pydantic>=2.3.0 \ No newline at end of file