1. Create and activate virtual environment
python3.6 -m venv <path-to-some-dir>/online_courses_api
source <path-to-some-dir>/online_courses_api/bin/activate
2. Install online_courses_api package
pip install git+https://github.com/sheh/online_courses_api
3. Run
run_app.py
run options:
--port: port default:5000
--db: path to sqlite file, default:$TMPDIR/online_courses_api.db
--drop-db: drop database before start
python3.6 -m venv <path-to-some-dir>/online_courses_api
source <path-to-some-dir>/online_courses_api/bin/activate
git clone https://github.com/sheh/online_courses_api
cd online_courses_api
pip install .
pip install pytest pytest-flask
pytest
...
collected 57 items
online_courses_api/tests/test_classes_specific.py ........
online_courses_api/tests/test_endpoints_common.py ...........................................
online_courses_api/tests/test_students_specific.py ......
=========================================================================== 57 passed in 0.89 seconds ============================================================================
- sqlite is used
- there are no verbose messages in case of errors, just http code
- only one param can be used for filtration (except filtration by
classandteacherfor according endpoints) - complete data structure should be
PUTfor update, a partial update is not supported
/teacher
POST /teacher- createGET /teacher?param=val- filter by paramGET /teacher/<id>- getPUT /teacher/<id>- updateDELETE /teacher/<id>- delete
/students
POST /students- createGET /students?param=val- filter by paramGET /students?class=<id>&class=<id>- filter by classesGET /students/<id>- getPUT /students/<id>- updateDELETE /students/<id>- deletePUT /students/<sid>/classes/<cid>- add studentsidto classcidDELETE /students/<sid>/classes/<cid>- delete studentsidfrom classcid
/classes
POST /classes- createGET /classes?param=val- filter by paramGET /classes?teacher=<id>&teacher=<id>- filter by teachersGET /classes/<id>- getPUT /classes/<id>- updateDELETE /classes/<id>- deletePUT /classes/<cid>/teacher/<tid>- bind classcidto teachertidDELETE /classes/<cid>/teacher/<tid>- unbind classcidfrom teachertid
(command http below is httpie tool pip install httpie)
1. Create a teacher:
http POST http://localhost:5000/teachers first_name=Joe last_name=Moon specs:='["math", "physics"]'
response:
{
"first_name": "Joe",
"id": 1,
"last_name": "Moon",
"specs": [
"math",
"physics"
]
}
2. Get the teacher:
http GET http://localhost:5000/teachers/1
response:
{
"first_name": "Joe",
"id": 1,
"last_name": "Moon",
"specs": [
"math",
"physics"
]
}
3. Filter teachers by a parameter:
http GET 'http://localhost:5000/teachers?first_name=Joe'
response:
{
"first_name": "Joe",
"id": 1,
"last_name": "Moon",
"specs": [
"math",
"physics"
]
}
4. Update a teacher
http PUT http://localhost:5000/teachers/1 first_name=Joseph last_name=Moon specs:='["math"]'
response:
{
"first_name": "Joseph",
"id": 1,
"last_name": "Moon",
"specs": [
"math"
]
}
5. Delete the teacher:
http DELETE 'http://localhost:5000/teachers/1'
response:
{}
6. Create class:
http POST http://localhost:5000/classes name=math description='A math class' spec=math
response:
{
"description": "A math class",
"id": 1,
"name": "math",
"spec": "math"
}
7. Bind class and teacher:
http PUT http://localhost:5000/classes/1/teacher/1
response:
{}
8. Filter classes by teacher:
http GET http://localhost:5000/classes?teacher=1
response:
[
{
"description": "A math class",
"id": 1,
"name": "math",
"spec": "math"
}
]
9. Create a student:
http POST http://localhost:5000/students first_name=Kelly last_name=Williams
response:
{
"first_name": "Kelly",
"id": 1,
"last_name": "Williams"
}
10. Add a student to class:
http PUT http://localhost:5000/students/1/classes/1
response:
{}
11. Filter students by class:
http GET http://localhost:5000/students?class=1
response:
[
{
"first_name": "Kelly",
"id": 1,
"last_name": "Williams"
}
]