Add endpoint to read CONTENT environment variable
- Created a new endpoint at /api/v1/env/content that returns the CONTENT environment variable - Added error handling for when the environment variable is not set - Updated documentation with new endpoint information and usage examples - Added environment variables as a new feature in README
This commit is contained in:
parent
783583b234
commit
1df01b998d
19
README.md
19
README.md
@ -7,6 +7,7 @@ A simple Todo API built with FastAPI and SQLite.
|
|||||||
- 📝 **Todo Management**: Create, read, update, and delete todo items
|
- 📝 **Todo Management**: Create, read, update, and delete todo items
|
||||||
- 🔍 **Filtering & Pagination**: Filter todos by completion status and paginate results
|
- 🔍 **Filtering & Pagination**: Filter todos by completion status and paginate results
|
||||||
- 📊 **Health Monitoring**: Endpoint to check application and database health
|
- 📊 **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
|
- 🛡️ **Error Handling**: Comprehensive error handling with meaningful messages
|
||||||
- 📚 **API Documentation**: Auto-generated Swagger/OpenAPI documentation
|
- 📚 **API Documentation**: Auto-generated Swagger/OpenAPI documentation
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ A simple Todo API built with FastAPI and SQLite.
|
|||||||
├── app/
|
├── app/
|
||||||
│ ├── api/
|
│ ├── api/
|
||||||
│ │ └── v1/
|
│ │ └── v1/
|
||||||
|
│ │ ├── env_vars.py # Environment variables endpoints
|
||||||
│ │ ├── health.py # Health check endpoint
|
│ │ ├── health.py # Health check endpoint
|
||||||
│ │ ├── router.py # API router
|
│ │ ├── router.py # API router
|
||||||
│ │ └── todos.py # Todo CRUD endpoints
|
│ │ └── todos.py # Todo CRUD endpoints
|
||||||
@ -99,6 +101,10 @@ Interactive API documentation is available at:
|
|||||||
- `PATCH /api/v1/todos/{todo_id}` - Update a todo
|
- `PATCH /api/v1/todos/{todo_id}` - Update a todo
|
||||||
- `DELETE /api/v1/todos/{todo_id}` - Delete 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
|
## Example Usage
|
||||||
|
|
||||||
### Create a Todo
|
### Create a Todo
|
||||||
@ -143,6 +149,19 @@ curl -X 'PATCH' \
|
|||||||
curl -X 'DELETE' 'http://localhost:8000/api/v1/todos/1'
|
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
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License.
|
This project is licensed under the MIT License.
|
33
app/api/v1/env_vars.py
Normal file
33
app/api/v1/env_vars.py
Normal file
@ -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}
|
@ -1,8 +1,9 @@
|
|||||||
from fastapi import APIRouter
|
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 = APIRouter()
|
||||||
|
|
||||||
api_router.include_router(health.router, tags=["health"])
|
api_router.include_router(health.router, tags=["health"])
|
||||||
api_router.include_router(todos.router, prefix="/todos", tags=["todos"])
|
api_router.include_router(todos.router, prefix="/todos", tags=["todos"])
|
||||||
|
api_router.include_router(env_vars.router, tags=["environment"])
|
Loading…
x
Reference in New Issue
Block a user