--- /dev/null
+##############################################################################\r
+# Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are made available under the terms of the Apache License, Version 2.0\r
+# which accompanies this distribution, and is available at\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+##############################################################################\r
+\r
+from flask import Flask\r
+from flask_cors import CORS\r
+from flask import request\r
+from flask import jsonify\r
+import time\r
+import json\r
+from random import randint\r
+\r
+app = Flask(__name__)\r
+CORS(app)\r
+\r
+\r
+@app.route("/greet")\r
+def greet():\r
+ return "hello"\r
+\r
+\r
+@app.route("/answer", methods=["POST"])\r
+def answer():\r
+ app.logger.debug(request.form)\r
+ app.logger.debug(request.data)\r
+ if jsonify(request.form) != {} and 'ping' in request.form:\r
+ return "answer: ping is: \"" + request.form['ping'] + "\" end."\r
+ elif request.data != "":\r
+ requestDict = json.loads(request.data)\r
+ if 'ping' in requestDict:\r
+ return "answer: the ping is: \"" + requestDict['ping'] + "\" end."\r
+ else:\r
+ return "answer ping is null"\r
+\r
+\r
+@app.route("/answer2", methods=["POST"])\r
+def answer2():\r
+ return "ok"\r
+\r
+\r
+@app.route("/five")\r
+def sleepFiveSeconds():\r
+ time.sleep(5)\r
+ return "five: receive the request."\r
+\r
+\r
+@app.route("/ten")\r
+def sleepTenSeconds():\r
+ time.sleep(10)\r
+ return "ten: receive the request."\r
+\r
+\r
+@app.route("/switch")\r
+def switchValue():\r
+ value = randint(0, 10)\r
+ if value > 4:\r
+ return jsonify({'code': 200, 'result': 'A'})\r
+ else:\r
+ return jsonify({'code': 200, 'result': 'B'})\r
+\r
+\r
+@app.route("/switch_2")\r
+def switchValue_2():\r
+ value = randint(0, 10)\r
+ if value > 4:\r
+ return jsonify({'code': 200, 'result': 'C'})\r
+ else:\r
+ return jsonify({'code': 200, 'result': 'D'})\r
+\r
+\r
+if __name__ == "__main__":\r
+ app.run(host='0.0.0.0', port=5312, debug=True)\r