-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_hello.py
38 lines (31 loc) · 948 Bytes
/
run_hello.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
37
38
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/hello', methods=['GET', 'POST'])
def hello_world():
return "Hello, world!"
@app.route('/hello/<name>', methods=['GET'])
def hello_name(name):
return f"Hello, {name}"
@app.route('/interesting/<name>', methods=['GET'])
def serve_html(name):
return f"""
<html>
<body>
<h1>Hello {name}</h1>
<p>This is my fancy webpage</p>
</body>
</html>
"""
@app.route('/sample_post', methods=['POST'])
def sample_post():
# Extract the json from the incoming request.
content = request.json
# Do some work on the content
if "text" not in content:
return jsonify({"error": "Required field 'text' is missing"}), 400
else:
print(content["text"])
# Return what you need when processing is done.
return jsonify({"text": content["text"]})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)