This is a Flask app with an API layer. It has the following properties:
- It has the following relational entities:
- Student
- Teacher
- Subject
- Each student can have only one subject as a major, but can read any subject as well (minors)
- A subject is taught by one teacher
- It has endpoints to CREATE, UPDATE, and DELETE each entity in the application
- Only an authorized user can access the endpoints
Clone the repo from GitHub:
git clone https://github.com/mbithenzomo/flask-student-api
Fetch from the develop branch:
git fetch origin develop
Navigate to the root folder:
cd flask-student-api
Install the required packages:
pip install -r requirements.txt
Create a .env
file with the following keys:
SECRET_KEY
DATABASE_URI - for SQLAlchemy
TEST_DATABASE_URI - for SQLAlchemy
ENVIRONMENT - this is either production or development
Initialize, migrate, and upgrade the database:
python manage.py db init
python manage.py db migrate
python manage.py db upgrade
Run python run.py
. You may use Postman for Google Chrome to run the API.
Resource URL | Methods | Description | Requires Token |
---|---|---|---|
/api/v1 |
GET | The index | FALSE |
/api/v1/auth/register |
POST | User registration | FALSE |
/api/v1/auth/login |
POST | User login | FALSE |
/api/v1/students |
GET, POST | View all students, add a student | TRUE |
/api/v1/students/<string:id> |
GET, PUT, DELETE | View, edit, and delete a single student | TRUE |
/api/v1/teachers |
GET, POST | View all teachers, add a teacher | TRUE |
/api/v1/teachers/<string:id> |
GET, PUT, DELETE | View, edit, and delete a single teacher | TRUE |
/api/v1/subjects |
GET, POST | View all subjects, add a subject | TRUE |
/api/v1/subjects/<string:id> |
GET, PUT, DELETE | View, edit, and delete a single subject | TRUE |
Registering and logging in to get a JWT token:
Displaying a paginated list of teachers:
Displaying a paginated list of subjects:
The app has a web-based interface and can be accessed here. A sample user has already been created with the following credentials:
username: testuser
password: testpassword
To test, run the following command: nose2
Copyright (c) 2018 Mbithe Nzomo