This repository contains a simple RESTful API built with Flask and SQLAlchemy. It exposes endpoints for creating, reading, updating, and deleting student records stored in a PostgreSQL database.
- CRUD endpoints for students
- PostgreSQL database integration via SQLAlchemy
- Dockerfile and Docker Compose setup
- Unit and end-to-end tests using pytest
- Python 3.11
- PostgreSQL database (or use Docker Compose)
pipfor installing dependencies
Clone the repository and install the dependencies:
pip install -r requirements.txtCreate a .env file or set the following environment variables for database configuration:
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_NAME=postgresEnsure PostgreSQL is running and the environment variables are set, then start the Flask app:
python app.pyThe API will be available at http://localhost:8888/api/student.
You can also run the app and database with Docker Compose:
docker-compose up --build| Method | Endpoint | Description |
|---|---|---|
| GET | /api/student |
Get all students (returns 404 if none). |
| POST | /api/student |
Add a new student (JSON with name, age, major). |
| PUT | /api/student/<id> |
Update a student's information. |
| DELETE | /api/student/<id> |
Delete a student by ID. |
With the application and database running, execute the tests with:
pytestThis runs both the unit tests and the end-to-end tests that interact with the running API.