-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (26 loc) · 771 Bytes
/
app.py
File metadata and controls
35 lines (26 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, request, jsonify
app = Flask(__name__)
todos = [
{ "label": "My first task", "done": False },
{ "label": "My second task", "done": False }
]
@app.route("/")
def home():
return "Hello Flask!"
@app.route("/myroute", methods=["GET"])
def hell0_world():
return "Hello World!"
@app.route("/todos", methods=["GET"])
def get_todos():
return jsonify(todos)
@app.route("/todos", methods=["POST"])
def add_new_todo():
request_body = request.json
todos.append(request_body)
return jsonify(todos), 200
@app.route("/todos/<int:position>", methods=["DELETE"])
def delete_todo(position):
todos.pop(position)
return jsonify(todos), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3245, debug=True)