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