Giter Site home page Giter Site logo

online_courses_api's Introduction

Install and Run

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

Run the tests

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 ============================================================================

Assumptions:

  • 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 and teacher for according endpoints)
  • complete data structure should be PUT for update, a partial update is not supported

The schema

/teacher

  • POST /teacher - create
  • GET /teacher?param=val - filter by param
  • GET /teacher/<id> - get
  • PUT /teacher/<id> - update
  • DELETE /teacher/<id> - delete

/students

  • POST /students - create
  • GET /students?param=val - filter by param
  • GET /students?class=<id>&class=<id> - filter by classes
  • GET /students/<id> - get
  • PUT /students/<id> - update
  • DELETE /students/<id> - delete
  • PUT /students/<sid>/classes/<cid> - add student sid to class cid
  • DELETE /students/<sid>/classes/<cid> - delete student sid from class cid

/classes

  • POST /classes - create
  • GET /classes?param=val - filter by param
  • GET /classes?teacher=<id>&teacher=<id> - filter by teachers
  • GET /classes/<id> - get
  • PUT /classes/<id> - update
  • DELETE /classes/<id> - delete
  • PUT /classes/<cid>/teacher/<tid> - bind class cid to teacher tid
  • DELETE /classes/<cid>/teacher/<tid> - unbind class cid from teacher tid

How it works

(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"
    }
]

online_courses_api's People

Contributors

sheh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.