-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator_controller.py
More file actions
79 lines (58 loc) · 2.01 KB
/
Copy pathcalculator_controller.py
File metadata and controls
79 lines (58 loc) · 2.01 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
###########################
# 1. import flask library
# HINT: sample/request_processing.py
###########################
import service.calculator as calculator
from http import HTTPStatus
from flask import jsonify, Flask, request
###########################
# 2. initialize your Flask application object
# HINT: sample/explicit_application_object.py
###########################
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World'
###########################
# 3. define route paths for the following functions with the specified path and method
# HINT: sample/routing.py
# 4. and parse the request to get the user_input given the request type
# HINT: sample/request_processing.py
###########################
# path = '/mean', method = 'GET'
# request type = JSON
@app.route('/mean', methods=['GET'])
def mean():
# user_input =
user_input = request.get_json()['input']
results = calculator.mean(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/median', method = 'GET and POST'
# request type = Query
@app.route('/median', methods=['GET','POST'])
def median():
# user_input =
user_input = request.args.get()['input']
user_input = list(map(int, user_input.split(',')))
results = calculator.median(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/mode', method = 'POST'
# request type = Form
@app.route('/mode', methods=['POST'])
def mode():
# user_input =
user_input = request.args.get()['input']
user_input = list(map(int, user_input))
results = calculator.mode(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/status', method = 'GET'
@app.route('/status', methods=['GET'])
def status():
result = "Application is running"
return result, HTTPStatus.OK
if __name__ == '__main__':
###########################
# 5. Start your flask app
# HINT: sample/explicit_application_object.py
###########################
app.run(host='0.0.0.0',port=8080)