Table of Contents
This is a Flask-RESTX API for managing student information and performance. The API includes endpoints for onboarding students, updating student's information, viewing student performance, and administrative functions such as adding new students, enrolling students to courses, adding performance and viewing all students. The API has two roles: teacher and student. The teacher role has the full access to all the endpoints, which means, a teacher can perform all CRUD operation on course and student namespaces, while the student role can only register as a student, update personal information, view their own information and course performance.
Here are the some of the endpoints for this project;
Onboard a new User (Student and Teacher)
POST /auth/register/student
Request body:
# Register as a Student
{
"email": "student@gmail.com",
"first_name": "Olubunmi",
"last_name": "Oluwatobi",
"password": "password"
}
POST /auth/register/teacher
Request body:
# Register as a Teacher
{
"email": "teacher@gmail.com",
"first_name": "Adekunle",
"last_name": "Olayinka",
"password": "password"
}
Update a student's information
PUT /students/<student_id>
Request body:
{
"email": "adewale@gmail.com",
"first_name": "Adewale",
"last_name": "John"
}
View a student's grade
GET /students/<student_id>/courses/grade
Response body:
[
{
"name": "BCH103",
"score": 80.0,
"grade": "B"
},
{
"name": "BCH102",
"score": 50.0,
"grade": "E"
},
{
"name": "BCH104",
"score": 89.0,
"grade": "B"
},
{
"name": "BCH105",
"score": 88.0,
"grade": "B"
},
{
"name": "BCH106",
"score": 81.0,
"grade": "B"
}
]
View all students
GET /students
Response body:
[
{
"id": "1",
"identifier": "8831",
"email": "s@gmail.com",
"first_name": "David",
"last_name": "Daniel",
"admission_no": "STD/23/8831"
},
{
"id": "3",
"identifier": "9317",
"email": "s1@gmail.com",
"first_name": "Odumade",
"last_name": "Babajide",
"admission_no": "STD/23/9317"
},
{
"id": "4",
"identifier": "2306",
"email": "s2@gmail.com",
"first_name": "Ogunmola",
"last_name": "Kayode",
"admission_no": "STD/23/2306"
},
{
"id": "5",
"identifier": "3415",
"email": "s3@gmail.com",
"first_name": "Iterogba",
"last_name": "Adeolu",
"admission_no": "STD/23/3415"
}
]
The API includes error handling for the following scenarios:
- Invalid request body: The API will return a 400 Bad Request response with a message indicating the issue with the request body.
- Student not found: The API will return a 404 Not Found response with a message indicating that the student with the specified ID was not found.
- Unauthorized access: The API will return a 401 Unauthorized response if the user attempts to access an endpoint that requires authentication without providing valid credentials.
- Internal server error: The API will return a 500 Internal Server Error response if an unexpected error occurs.
- How to set up a Flask API with Flask-RESTX
- Databases with Flask-SQLAlchemy
- JWT Authentication with Flask-JWT-Extended
- Environment variables with Python-Decouple
- Database migrations with Flask-Migrate
- How to write Unit Tests with Unittest and PyTest
- Documenting REST APIs with SwaggerUI and Flask-RESTX
- Error Handling
- Flask API Deployment via Heroku
Clone the project Repository
git clone https://github.com/BrodaOJ56/Student-Management-API/
Enter the project folder
$ cd Student-Management-API
Install all requirements
$ pip install -r requirements.txt
Export to run the project in development environment
export FLASK_APP=api/
echo FLASK_APP
Create database
flask db init
flask db migrate -m "your description"
flask run
To use this API, on live server:
- Open the web API on your browser: https://student-management-flask-api.herokuapp.com/
Create a student or teacher account:
-
Click 'auth' to reveal a dropdown menu of auth routes, then register as either as a student or teacher.
-
Sign in via the '/auth/login' route to generate a JWT token. Copy this access token without the quotation marks
-
Scroll up to click 'Authorize' at top right. Enter the JWT token in the given format, Bearer for example:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY3OTE1NTM5MywianRpIjoiMGQ1MGFlNWUtZTAyMy00ZDI3LTg3MjAtNTFmMzg0NWJkZGRkIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6MiwibmJmIjoxNjc5MTU1MzkzLCJleHAiOjE2NzkyNDE3OTN9.Mr-uZ2Ne6H-RAGgooQq0jOuORCmdRnCqa3K1nCUlHQA
-
Click 'Authorize' and then 'Close'
-
Now authorized as either a student or teacher, you now perform various operations via the many routes in 'students', 'courses' endpoints'.
-
When you're done, click 'Authorize' at top right again to then 'Logout'
This Flask-RESTX API provides a basic framework for managing student information and performance. With the endpoints provided, a teacher can onboard new students and view all students in the system, while students can update their basic information and view their performance. The API is extensible and could be expanded to include additional functionality as needed.
Distributed under the MIT License. See LICENSE for more information.
OLUBUNMI OLUWATOBI JAMES - @ItzOfficialOJ
This project was made possible by: