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
class
andteacher
for according endpoints) - complete data structure should be
PUT
for 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 studentsid
to classcid
DELETE /students/<sid>/classes/<cid>
- delete studentsid
from 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 classcid
to teachertid
DELETE /classes/<cid>/teacher/<tid>
- unbind classcid
from 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"
}
]