-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_no_cache.py
36 lines (27 loc) · 970 Bytes
/
api_no_cache.py
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
from flask import Flask
from flask import request
import os
from db.data_layer_no_cache import DataLayerNoCache
app = Flask(__name__)
data_layer = DataLayerNoCache()
@app.route("/dob/<string:user_id>", methods=['GET', 'PUT', 'DELETE'])
def dob(user_id):
if request.method == 'GET':
print(f'API: Getting Date of birth for user id: {user_id}')
dob = data_layer.get_dob(user_id)
return str(dob)
elif request.method == 'PUT':
dob = request.args.get('dob')
data_layer.set_dob(user_id, dob)
return 'OK'
else:
# DELETE DOB
data_layer.delete_dob(user_id)
return 'OK'
@app.route("/populate_db", methods=['POST'])
def populate_db():
data_layer.populate_db(int(request.args.get('num_dobs')))
return 'OK'
if __name__ == "__main__":
# Heroku provides environment variable 'PORT' that should be listened on by Flask
app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))