Last active
October 8, 2020 15:12
-
-
Save beanyoung/8318363 to your computer and use it in GitHub Desktop.
thrift server based on flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, make_response | |
from thrift.protocol import TBinaryProtocol | |
from thrift.server import TServer | |
from thrift.transport import TTransport | |
from FooService import FooService | |
from foo_service_handler import FooServiceHandler | |
foo_handler = FooServiceHandler() | |
foo_processor = FooService.Processor(foo_handler) | |
foo_pfactory = TBinaryProtocol.TBinaryProtocolFactory() | |
foo_server = TServer.TServer( | |
foo_processor, | |
None, None, None, | |
foo_pfactory, | |
foo_pfactory) | |
app = Flask(__name__) | |
app.config.from_object('config') | |
@app.route('/', methods=['POST']) | |
def profile_service_api(): | |
itrans = TTransport.TMemoryBuffer(request.data) | |
otrans = TTransport.TMemoryBuffer() | |
iprot = foo_server.inputProtocolFactory.getProtocol(itrans) | |
oprot = foo_server.outputProtocolFactory.getProtocol(otrans) | |
foo_server.processor.process(iprot, oprot) | |
return make_response(otrans.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet.