A simple RESTful API built with Flask for managing student records. This application provides CRUD (Create, Read, Update, Delete) operations for student data with SQLite database support.
- GET /api/v1/students - Retrieve all students
- GET /api/v1/students/{id} - Retrieve a specific student by ID
- POST /api/v1/students - Create a new student
- PUT /api/v1/students/{id} - Update an existing student
- DELETE /api/v1/students/{id} - Delete a student
- GET /healthcheck - API health status
- Flask - Web framework
- SQLAlchemy - ORM for database operations
- Flask-Migrate - Database migration support
- SQLite - Database (configurable via environment variables)
- Python-dotenv - Environment variable management
- Python 3.7 or higher
- Make (optional, for using Makefile commands)
- Docker (optional)
- Docker-compose (optional)
- Vagrant (optional)
- VirtualBox (for Vagrant)
- Minikube (Docker Required)
- Clone the repository:
git clone <repository-url>
cd student-management-api- Create a virtual environment and install dependencies:
make venv/bin/activateOr manually:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Create a
.envfile in the root directory(for developement):
DB_URL=postgresql://user:password@host:port/dbname
POSTGRES_DB=mydatabase
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypasswordmake serve-devThis will:
- Run database migrations
- Start the Flask development server on
http://localhost:5000
make serve-prodThis will:
- Run database migrations
- Start the application using Gunicorn
If you have Docker.You can use the below commands:
make build
make serve-dockerIf you want to use Vagrant.You can use the below commands:
sudo make serve-vagrantIf you want to use Minikube.You can use the below commands:
make minikube-setup # this will setup a (1+3) node cluster
make minikube-start # Resume the cluster
make minikube-stop # Pause the cluster
#Once the minikube cluster is up and healthy
make minikube-deploy # this will deploy the applicationMake sure to update DB details in the k8s/scripts/vault_setup.sh For the Minikube approach for now I am using a hack for setting up the permissions on the the hostpath volume as a workaround to that bug. Link to github Issue
- id (Integer, Primary Key) - Auto-generated student ID
- first_name (String, Required) - Student's first name
- last_name (String, Required) - Student's last name
- age (Integer, Required) - Student's age
- email (String, Required, Unique) - Student's email address
{
"first_name": "a",
"last_name": "b",
"age": 10,
"email": "asdc3@gmail.com"
}To create a new migration:
make migratesource venv/bin/activate
python -m pytest tests/ -vTo remove virtual environment and cache files:
make cleanThe application uses environment variables for configuration:
- DB_URL - Database connection string (Example: sqlite:///students.db or postgresql://user:password@host:port/dbname)
- POSTGRES_DB - Database Name (Only if using postgres)
- POSTGRES_USER - Database Username (Only if using postgres)
- POSTGRES_PASSWORD - Database Password (Only if using postgres)
student-management-api/
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── Makefile # Build and deployment commands
├── .env # Environment variables
├── migrations/ # Database migration files
├── tests/ # Unit tests
└── README.md # This file