-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrunserver.py
More file actions
95 lines (69 loc) · 2.46 KB
/
Copy pathrunserver.py
File metadata and controls
95 lines (69 loc) · 2.46 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
#############################################
# PUBLISH SAMPLE FLASK APPLICATION
# IN AZURE WEB APP FOR CONTAINERS
#############################################
# This is just simplest helloworld + API
# application written in python
# using flask
#############################################
# (c) Janne Hansen 2018, MIT LICENCE
#############################################
#imports
from flask import Flask
from flask import request
from flask import make_response
from flask import render_template
# for the api
import json
import logging
#############################################
# FLASK STUFF
#############################################
app = Flask(__name__)
# Just that we have a start page for the web application
@app.route("/")
def hello():
# https://www.tutorialspoint.com/flask/flask_templates.htm
app.logger.info("hello called")
return render_template("hello.html"),200
# The api method. Expects a parameter named "input"
@app.route("/api", methods=["GET"])
def api():
retdict ={}
try:
input_string = request.args.get("input","[you forgot to feed in input]")
app.logger.info("FAKE API CALL, input = "+input_string)
response = {
'input':input_string,
'my_api_output':"hello api "+input_string
}
retdict['response']=response
except Exception as e:
msg = "Bad Request (400): "+str(e)
app.logger.info(msg)
# print(msg)
return msg,400
retJson = json.dumps(retdict)
app.logger.info("retjson :"+retJson)
resp = make_response(retJson)
resp.headers['content-type']="application/json"
# http://www.flaskapi.org/api-guide/status-codes/#successful-2xx
return resp, 200
#############################################
# MAIN
#############################################
if __name__=='__main__':
# Set the logger level
app.logger.setLevel(logging.INFO)
# And now to work
app.logger.info("PythonFlaskApp starting....")
# If you had something to initialize before we start the server
# this would be the place to do just that.
# Run the flask app
# Flask app default port is 5000
app.run(debug=True,host='0.0.0.0')
app.logger.info("PythonFlaskApp Finished.")
#############################################
# END OF FILE
#############################################