Exemple #1
0
from flask import Flask, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

todos = {}


class TodoSimple(Resource):
    def get(self, todo_id):
        return {todo_id: todos[todo_id]}

    def put(self, todo_id):
        todos[todo_id] = request.form['data']
        return {todo_id: todos[todo_id]}


api.add_resource(TodoSimple, '/<string:todo_id>')
api.add_resurce(HelloWolrd, '/', '/hello')

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=8001)
        if args.on == True:
            call("middle_earth.py living-room on")
        if args.off == True:
            call("middle_earth.py living-room off")
        if args.dim == True:
            call("middle_earth.py living-room dim")
        if args.night == True:
            call("middle_earth.py living-room night")
        return 201


class kittyCorner(Resource):
    def post(self):
        args = parser.parse_args()
        if args.on == True:
            call("middle_earth.py kitty-corner on")
        if args.off == True:
            call("middle_earth.py kitty-corner off")
        if args.dim == True:
            call("middle_earth.py kitty-corner dim")
        if args.night == True:
            call("middle_earth.py kitty-corner night")
        return 201


api.add_resurce(livingRoom, "/livingroom")
api.add_resurce(kittyCorner, "/kittycorner")

if __name__ == "__main__":
    app.run()