-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (25 loc) · 842 Bytes
/
app.py
File metadata and controls
30 lines (25 loc) · 842 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
from flask import Flask, jsonify, request
app = Flask(__name__)
todos = [
{ "label": "My first task", "done": False },
{ "label": "Brush my teeth", "done": False },
{ "label": "Dry my hair", "done": False }
]
@app.route('/todos', methods=['GET'])
def hello_world():
json_text=jsonify(todos)
return json_text
@app.route('/todos', methods=['POST'])
def add_new_todo():
request_body = request.json
request.get_json(force=True)
print("Incoming request with the following body", request_body)
todos.append(request_body)
return jsonify(todos)
@app.route('/todos/<int:position>', methods=['DELETE'])
def delete_todo(position):
print("This is the position to delete:", position)
todos.pop(position)
return jsonify(todos)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3245, debug=True)