基于flask构建微服基本demo

利用flask简单快捷特性,作为构建微服务的基础。
class BaseService(object):
    def __init__(self,uri,host="0.0.0.0",port=5002):
        self.app = Flask("sparrow")
        self.uri = uri
        self.port = port
        self.host =host

    def ping(self):
        return "ping success"

    def setting(self):
        return "setting success"

    def process(self):
        return "process success"

    def start(self):
        self.app.add_url_rule(self.uri+"/ping", view_func=self.ping,methods=['GET'])
        self.app.add_url_rule(self.uri + "/setting", view_func=self.setting, methods=['POST'])
        self.app.add_url_rule(self.uri, view_func=self.process, methods=['POST'])
        self.app.run(host=self.host, port=self.port)
class sparrowApp(BaseService):
    def __init__(self):
        self.uri = "/sparrowApp"
        BaseService.__init__(self,uri=self.uri,host="127.0.0.1")

    def ping(self):
        return "ping success"

    def setting(self):
        return "setting success"

    def process(self):
        return "process success"

if __name__ == '__main__':
    service = sparrowApp()
    service.start()
swagger

你可能感兴趣的:(微服务)