Add Hello World FastAPI application with health endpoint

generated with BackendIM... (backend.im)
This commit is contained in:
Automated Action 2025-05-13 05:23:42 +00:00
parent 9a83d94792
commit 2e449f5437
3 changed files with 86 additions and 2 deletions

View File

@ -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

38
main.py Normal file
View File

@ -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)

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
fastapi>=0.103.1
uvicorn>=0.23.2
sqlalchemy>=2.0.20
pydantic>=2.3.0