diff --git a/README.md b/README.md index 83731ab..b198fef 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ A simple Todo API built with FastAPI and SQLite. - 📝 **Todo Management**: Create, read, update, and delete todo items - 🔍 **Filtering & Pagination**: Filter todos by completion status and paginate results - 📊 **Health Monitoring**: Endpoint to check application and database health +- 🔧 **Environment Variables**: Access to environment variables via API - 🛡️ **Error Handling**: Comprehensive error handling with meaningful messages - 📚 **API Documentation**: Auto-generated Swagger/OpenAPI documentation @@ -25,6 +26,7 @@ A simple Todo API built with FastAPI and SQLite. ├── app/ │ ├── api/ │ │ └── v1/ +│ │ ├── env_vars.py # Environment variables endpoints │ │ ├── health.py # Health check endpoint │ │ ├── router.py # API router │ │ └── todos.py # Todo CRUD endpoints @@ -99,6 +101,10 @@ Interactive API documentation is available at: - `PATCH /api/v1/todos/{todo_id}` - Update a todo - `DELETE /api/v1/todos/{todo_id}` - Delete a todo +### Environment Variables Endpoints + +- `GET /api/v1/env/content` - Get the value of the CONTENT environment variable + ## Example Usage ### Create a Todo @@ -143,6 +149,19 @@ curl -X 'PATCH' \ curl -X 'DELETE' 'http://localhost:8000/api/v1/todos/1' ``` +### Get CONTENT Environment Variable + +```bash +curl -X 'GET' 'http://localhost:8000/api/v1/env/content' +``` + +To set the environment variable before running the application: + +```bash +export CONTENT="Your content here" +uvicorn main:app --host 0.0.0.0 --port 8000 --reload +``` + ## License This project is licensed under the MIT License. \ No newline at end of file diff --git a/app/api/v1/env_vars.py b/app/api/v1/env_vars.py new file mode 100644 index 0000000..a3a6470 --- /dev/null +++ b/app/api/v1/env_vars.py @@ -0,0 +1,33 @@ +import os +from typing import Dict + +from fastapi import APIRouter, HTTPException, status + +router = APIRouter() + + +@router.get( + "/env/content", + response_model=Dict[str, str], + summary="Get content from CONTENT environment variable", + description="Returns the value of the CONTENT environment variable" +) +def get_content_env_var(): + """ + Retrieve the value of the CONTENT environment variable. + + Returns: + dict: A dictionary containing the CONTENT environment variable value + + Raises: + HTTPException: If the CONTENT environment variable is not set + """ + content_value = os.environ.get("CONTENT") + + if content_value is None: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="CONTENT environment variable is not set" + ) + + return {"content": content_value} \ No newline at end of file diff --git a/app/api/v1/router.py b/app/api/v1/router.py index afd6dd5..7add3ed 100644 --- a/app/api/v1/router.py +++ b/app/api/v1/router.py @@ -1,8 +1,9 @@ from fastapi import APIRouter -from app.api.v1 import health, todos +from app.api.v1 import env_vars, health, todos api_router = APIRouter() api_router.include_router(health.router, tags=["health"]) -api_router.include_router(todos.router, prefix="/todos", tags=["todos"]) \ No newline at end of file +api_router.include_router(todos.router, prefix="/todos", tags=["todos"]) +api_router.include_router(env_vars.router, tags=["environment"]) \ No newline at end of file