1 ##############################################################################
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from flask import Flask
11 from flask_cors import CORS
12 from flask import request
13 from flask import jsonify
16 from random import randint
27 @app.route("/answer", methods=["POST"])
29 app.logger.debug(request.form)
30 app.logger.debug(request.data)
31 if jsonify(request.form) != {} and 'ping' in request.form:
32 return "answer: ping is: \"" + request.form['ping'] + "\" end."
33 elif request.data != "":
34 requestDict = json.loads(request.data)
35 if 'ping' in requestDict:
36 return "answer: the ping is: \"" + requestDict['ping'] + "\" end."
38 return "answer ping is null"
41 @app.route("/answer2", methods=["POST"])
47 def sleepFiveSeconds():
49 return "five: receive the request."
53 def sleepTenSeconds():
55 return "ten: receive the request."
60 value = randint(0, 10)
62 return jsonify({'code': 200, 'result': 'A'})
64 return jsonify({'code': 200, 'result': 'B'})
67 @app.route("/switch_2")
69 value = randint(0, 10)
71 return jsonify({'code': 200, 'result': 'C'})
73 return jsonify({'code': 200, 'result': 'D'})
76 if __name__ == "__main__":
77 app.run(host='0.0.0.0', port=5312, debug=True)