-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflaskapp.py
More file actions
42 lines (29 loc) · 815 Bytes
/
flaskapp.py
File metadata and controls
42 lines (29 loc) · 815 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
36
37
38
39
40
41
42
import json
from flask import Flask, request
app = Flask(__name__)
yaks = [
{'text': 'Hello world', 'votes': 5},
{'text': 'This is a yak', 'votes': -2}
]
@app.route("/", methods=['GET'])
def mainpage():
return app.send_static_file('index.html')
@app.route("/yak", methods=['POST'])
def addyak():
yaks.insert(0, request.get_json())
return "okay"
@app.route("/yaks", methods=['GET'])
def getyaks():
return json.dumps(yaks)
@app.route("/upvote", methods=['POST'])
def upvote():
yak = request.get_json()['id']
yaks[yak]['votes'] += 1
return "okay"
@app.route("/downvote", methods=['POST'])
def downvote():
yak = request.get_json()['id']
yaks[yak]['votes'] -= 1
return "okay"
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)