REST API developed with FastAPI for managing students, courses, enrollments and grades.
The project includes authentication with JWT, relational database modeling with MySQL, request validation with Pydantic and automatic API documentation using Swagger UI.
This API was built as a backend portfolio project to demonstrate:
- REST API development
- Database design with relationships
- CRUD operations
- JWT authentication
- Request and response validation
- SQLAlchemy ORM usage
- MySQL integration
- API documentation with Swagger UI
- Python 3
- FastAPI
- MySQL
- SQLAlchemy
- Pydantic
- PyMySQL
- Python-Jose
- Passlib
- Bcrypt
- Uvicorn
- Python Dotenv
- User registration
- User login with JWT token
- Protected endpoints using Bearer Token
- Student CRUD
- Course CRUD
- Student enrollment in courses
- Grade management
- Student grade consultation
- Automatic API documentation with Swagger UI
Clone the repository:
git clone https://github.com/Santlas09/student-system-api.git
cd student-system-apiCreate a virtual environment:
python -m venv venvActivate the virtual environment on Windows:
venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtCreate a .env file in the root directory and configure the following variables:
DATABASE_URL=mysql+pymysql://student_api_user:StudentApi123@localhost:3306/student_system_api
SECRET_KEY=change_this_secret_key_in_production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60Create the MySQL database:
CREATE DATABASE student_system_api
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;Optional: create a dedicated database user:
CREATE USER 'student_api_user'@'localhost' IDENTIFIED BY 'StudentApi123';
GRANT ALL PRIVILEGES ON student_system_api.* TO 'student_api_user'@'localhost';
FLUSH PRIVILEGES;Start the development server:
uvicorn app.main:app --reloadThe API will be available at:
http://localhost:8000Swagger documentation:
http://localhost:8000/docsPOST /auth/registerRequest body:
{
"full_name": "Santiago Reyes Herrera",
"email": "santiago@example.com",
"password": "123456"
}POST /auth/loginRequest body:
{
"email": "santiago@example.com",
"password": "123456"
}Response:
{
"access_token": "your_jwt_token_here",
"token_type": "bearer"
}Protected endpoints require this header:
Authorization: Bearer your_jwt_token_here| Method | Endpoint | Description | Protected |
|---|---|---|---|
| POST | /auth/register |
Register a new user | No |
| POST | /auth/login |
Login user and get token | No |
| GET | /auth/me |
Get current authenticated user | Yes |
| Method | Endpoint | Description | Protected |
|---|---|---|---|
| GET | /students/ |
List all students | No |
| POST | /students/ |
Create student | Yes |
| GET | /students/{student_id} |
Get student by ID | No |
| PUT | /students/{student_id} |
Update student | Yes |
| DELETE | /students/{student_id} |
Delete student | Yes |
| Method | Endpoint | Description | Protected |
|---|---|---|---|
| GET | /courses/ |
List all courses | No |
| POST | /courses/ |
Create course | Yes |
| GET | /courses/{course_id} |
Get course by ID | No |
| PUT | /courses/{course_id} |
Update course | Yes |
| DELETE | /courses/{course_id} |
Delete course | Yes |
| Method | Endpoint | Description | Protected |
|---|---|---|---|
| GET | /enrollments/ |
List enrollments | No |
| POST | /enrollments/ |
Enroll student in course | Yes |
| GET | /enrollments/{enrollment_id} |
Get enrollment by ID | No |
| GET | /enrollments/student/{student_id} |
Get enrollments by student | No |
| DELETE | /enrollments/{enrollment_id} |
Delete enrollment | Yes |
| Method | Endpoint | Description | Protected |
|---|---|---|---|
| GET | /grades/ |
List grades | No |
| POST | /grades/ |
Create grade | Yes |
| GET | /grades/{grade_id} |
Get grade by ID | No |
| PUT | /grades/{grade_id} |
Update grade | Yes |
| DELETE | /grades/{grade_id} |
Delete grade | Yes |
| GET | /students/{student_id}/grades |
Get student grades | No |
POST /students/
Content-Type: application/json
Authorization: Bearer your_jwt_token_here{
"first_name": "Santiago",
"last_name": "Reyes",
"email": "student1@example.com",
"age": 22
}POST /courses/
Content-Type: application/json
Authorization: Bearer your_jwt_token_here{
"name": "Programming Fundamentals",
"code": "PROG101",
"description": "Introduction to programming logic using Python.",
"credits": 3
}POST /enrollments/
Content-Type: application/json
Authorization: Bearer your_jwt_token_here{
"student_id": 1,
"course_id": 1
}POST /grades/
Content-Type: application/json
Authorization: Bearer your_jwt_token_here{
"enrollment_id": 1,
"title": "First Exam",
"score": 4.5,
"max_score": 5.0
}GET /students/1/gradesExample response:
[
{
"grade_id": 1,
"student_id": 1,
"student_name": "Santiago Reyes",
"course_id": 1,
"course_name": "Programming Fundamentals",
"course_code": "PROG101",
"title": "First Exam",
"score": 4.5,
"max_score": 5.0,
"created_at": "2026-06-07T00:00:00"
}
]You can test the API using:
- Swagger UI:
http://localhost:8000/docs - REST Client extension in VS Code
- Postman
- Hoppscotch
The project includes an api_tests.http file with ready-to-use requests.
- Passwords are stored as hashes.
- JWT tokens are required for protected endpoints.
- Sensitive values are stored in
.env. - The
.envfile should not be uploaded to GitHub. - A
.env.examplefile is included to show the required environment variables without exposing real credentials.
Santiago Reyes Herrera Systems Engineering Student Cartagena, Colombia
GitHub: Santlas09



