-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathapp.py
More file actions
26 lines (21 loc) · 767 Bytes
/
app.py
File metadata and controls
26 lines (21 loc) · 767 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
from flask import Flask, jsonify, request
app = Flask(__name__)
todos = [ { "label": "example task", "done": False }, ]
@app.route('/todos', methods=['GET'])
def hello_world():
todos_text = jsonify(todos)
return todos_text
@app.route('/todos', methods= ['POST'])
def add_new_todo():
request_body = request.json
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)
# These two lines should always be at the end of your app.py file
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3245, debug=True)