This is a Python FastAPI application that provides REST endpoints for generating test data files in CSV format.
- CSV Generation Endpoint: POST
/generate-csv- Creates a CSV file with test data based on the number of enrollments requested - Health Check: GET
/health- Simple health check endpoint
- Python 3.12
-
Create and activate virtual environment:
python3.12 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python -m src.main
Or using uvicorn directly:
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000
-
Access the API:
- API will be available at: http://localhost:8000
- Interactive API docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
curl -X POST "http://localhost:8000/generate-csv" \
-H "Content-Type: application/json" \
-d '{"numberOfEnrollments": 5}' \
--output enrollments.csvcurl http://localhost:8000/health- Docker installed on your system
-
Build the Docker image:
docker build -t api-app . -
Run the container:
docker run -p 8000:8000 api-app
-
Run with file logging enabled:
docker run -p 8000:8000 -e ENABLE_FILE_LOGGING=true api-app
-
Run in detached mode:
docker run -d -p 8000:8000 --name api-app-container api-app
-
Access the API:
- API will be available at: http://localhost:8000
- Interactive API docs: http://localhost:8000/docs
# Stop the container
docker stop api-app-container
# Start the container
docker start api-app-container
# View logs
docker logs api-app-container
# Remove container
docker rm api-app-container
# Remove image
docker rmi api-app# Run tests
pytest tests/test_main.py -v
# Run tests with coverage report
pytest tests/test_main.py -v --cov=src --cov-report=html --cov-report=termapi-app/
├── src/ # Source code directory
│ ├── main.py # FastAPI application entry point
│ ├── api/ # API layer
│ │ └── endpoints/ # API endpoint handlers
│ │ ├── csv.py # CSV generation endpoint
│ │ └── health.py # Health check endpoint
│ ├── config/ # Configuration modules
│ │ └── logging.py # Logging configuration
│ ├── middleware/ # FastAPI middleware
│ │ └── logging.py # Request logging middleware
│ ├── models/ # Pydantic data models
│ └── services/ # Business logic services
├── tests/ # Test directory
├── requirements.txt # Python dependencies