You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star0 (0)You must be signed in to star a repository
About
A Backend REST API for Managing Student EnrollmentsStudent Enrollment System is a FastAPI application that handles students, courses, and enrollments through clean CRUD endpoints, backed by SQLAlchemy and SQLite.
Pydantic validates data automatically. If a request sends the wrong type, FastAPI returns a 422 Unprocessable Entity error with details.
classStudentCreate(BaseModel):
name: str# Required, must be stringemail: EmailStr# Required, must be valid email formatphone: Optional[str] =None# Optional field
What is SQLAlchemy ORM?
ORM (Object-Relational Mapper) lets you work with database rows as Python objects:
# Without ORM (raw SQL):cursor.execute("INSERT INTO students (name, email) VALUES (?, ?)", (name, email))
# With SQLAlchemy ORM:student=Student(name="Ravi", email="ravi@example.com")
db.add(student)
db.commit()
What is Dependency Injection?
FastAPI's Depends() provides shared resources like DB sessions to every route function:
defget_student(student_id: int, db: Session=Depends(get_db)):
# db is automatically injected and closed after the request
🧪 Sample Requests (curl)
# Create a student
curl -X POST "http://localhost:8000/api/v1/students/" \
-H "Content-Type: application/json" \
-d '{"name": "Ravi Kumar", "email": "ravi@test.com"}'# Get all students
curl "http://localhost:8000/api/v1/students/"# Update a student
curl -X PUT "http://localhost:8000/api/v1/students/1" \
-H "Content-Type: application/json" \
-d '{"bio": "Updated bio"}'# Delete a student
curl -X DELETE "http://localhost:8000/api/v1/students/1"
🎯 Mentorship Exercises
Easy: Add a search query parameter to GET /students to filter by name
Medium: Add a new Mentor model with a one-to-many relationship to students
Hard: Add JWT authentication so only logged-in users can DELETE records
Built for Tech Mentorship Session — Happy Coding! 🎉
About
A Backend REST API for Managing Student EnrollmentsStudent Enrollment System is a FastAPI application that handles students, courses, and enrollments through clean CRUD endpoints, backed by SQLAlchemy and SQLite.