from flask import request, Blueprint, jsonify import helloworld_pb2 simulation_blueprint = Blueprint('simulation_blueprint', __name__) class SimulationController: def __init__(self): pass def harmonic_progression(self, n): sum = 0 for i in range(1, n): sum += 1/i return sum def return_helloworld(self): return jsonify(message="Hello World!") simulation_controller = SimulationController() @simulation_blueprint.route('/simulation/harmonic-progression', methods=['GET']) def return_ok(): n = int(request.args.get('n')) sum = simulation_controller.harmonic_progression(n) return str(sum), 200 @simulation_blueprint.route('/simulation/json', methods=['GET']) def return_helloworld(): return simulation_controller.return_helloworld(), 200 @simulation_blueprint.route('/simulation/protobuf', methods=['POST']) def return_protobuf(): bytes_data = request.data helloworld = helloworld_pb2.MyObj() helloworld.ParseFromString(bytes_data) return helloworld.SerializeToString(), 200