From 8cc28b369f58453669203c05600ff9add4cdb013 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 5 Jun 2025 12:07:08 +0000 Subject: [PATCH] Add endpoint to return NAME environment variable --- README.md | 10 +++++++++- app/core/config.py | 5 ++++- main.py | 13 ++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eb2e6e3..e18ad29 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,14 @@ This is a REST API built with FastAPI and SQLite. It provides endpoints for mana pip install -r requirements.txt ``` -3. Create and migrate database: +3. Set up environment variables (optional): + +```bash +# Create a .env file or set these in your environment +NAME=YourNameValue +``` + +4. Create and migrate database: ```bash # The storage directory and database will be created automatically when running the app @@ -53,6 +60,7 @@ Once the application is running, you can access: - `GET /`: API information - `GET /health`: Health check endpoint +- `GET /env/name`: Returns the value of the NAME environment variable - `GET /api/v1/items`: List all items - `POST /api/v1/items`: Create a new item - `GET /api/v1/items/{id}`: Get an item by ID diff --git a/app/core/config.py b/app/core/config.py index ddb22cb..1c9ef98 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import List +from typing import List, Optional from pydantic import validator from pydantic_settings import BaseSettings @@ -9,6 +9,9 @@ class Settings(BaseSettings): API_V1_STR: str = "/api/v1" PROJECT_NAME: str = "Generic REST API" + # Environment variables + NAME: Optional[str] = None + # CORS Configuration BACKEND_CORS_ORIGINS: List[str] = ["*"] diff --git a/main.py b/main.py index ccdf9f0..d4de590 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,12 @@ app.include_router(api_router, prefix=settings.API_V1_STR) @app.get("/") async def root(): """Root endpoint with API information.""" - return {"name": settings.PROJECT_NAME, "docs": "/docs", "health_check": "/health"} + return { + "name": settings.PROJECT_NAME, + "docs": "/docs", + "health_check": "/health", + "env_name": "/env/name", + } @app.get("/health", status_code=200) @@ -35,6 +40,12 @@ async def health_check(): return {"status": "healthy"} +@app.get("/env/name") +async def get_name_env(): + """Return the value of the NAME environment variable.""" + return {"name": settings.NAME} + + def custom_openapi(): if app.openapi_schema: return app.openapi_schema