如何从邮递员接收 uuid 到龙卷风应用程序中?
how to receive uuid from postman into tornado application?
我已经使用 uuid 将我的模型保存在弹性数据库中,我使用该 uuid 从 Postman 调用我的 tornado 应用程序,uuid 有我的模型,我应该如何在 POST 方法中接收它我的requestHandler,下面是代码
class myHandler(RequestHandler):
_thread_pool = ThreadPoolExecutor(max_workers=10)
#My data base url
def initialize(self):
self.db = self.settings['db']
#POST method to receive data and model
@gen.coroutine
def post(self, model_id):
try:
data = tornado.escape.json_decode(self.request.body)
yield self.predict(model_id, self.db, data)
except Exception:
self.respond('server_error', 500)
###here I have predict methods that receive the model_id and pass###
post 方法参数中的 model_id 是我从 postman
收到的 uuid
我的应用程序调用看起来像
elastic_url = os.environ.get('ELASTICSEARCH_URL', 'localhost:9200')
define('port', default=8888, help='Tornado port to listen on')
def make_app():
url = [(r"/uuid/predict", myHandler)]
return Application(url, db=elastic_url, debug=True, autoreload=False)
if __name__ == "__main__":
application = make_app()
http_server = HTTPServer(application)
http_server.listen(options.port)
IOLoop.current().start()
来自 POSTMAN 我将 API 称为
http://127.0.0.1:8888/9cd68748-a3b5-4bc3-994d-16e921103cb2/predict
如果我没有 uuid,我只需使用正则表达式接收,如下所示
url = [(r"/(?P<id>[a-zA-Z0-9_]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/model_name/predict
匹配 url 中的名称 'model_id' 和 post 函数
@gen.coroutine
def post(self, model_id):
try:
data = tornado.escape.json_decode(self.request.body)
yield self.predict(model_id, self.db, data)
except Exception:
self.respond('server_error', 500)
并使用 url 如下
url = [(r"/(?P<model_id>[a-zA-Z0-9_.-]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/d460e889-6860-4fb4-b040-fee70c96a029.mods/predict
我已经使用 uuid 将我的模型保存在弹性数据库中,我使用该 uuid 从 Postman 调用我的 tornado 应用程序,uuid 有我的模型,我应该如何在 POST 方法中接收它我的requestHandler,下面是代码
class myHandler(RequestHandler):
_thread_pool = ThreadPoolExecutor(max_workers=10)
#My data base url
def initialize(self):
self.db = self.settings['db']
#POST method to receive data and model
@gen.coroutine
def post(self, model_id):
try:
data = tornado.escape.json_decode(self.request.body)
yield self.predict(model_id, self.db, data)
except Exception:
self.respond('server_error', 500)
###here I have predict methods that receive the model_id and pass###
post 方法参数中的 model_id 是我从 postman
收到的 uuid我的应用程序调用看起来像
elastic_url = os.environ.get('ELASTICSEARCH_URL', 'localhost:9200')
define('port', default=8888, help='Tornado port to listen on')
def make_app():
url = [(r"/uuid/predict", myHandler)]
return Application(url, db=elastic_url, debug=True, autoreload=False)
if __name__ == "__main__":
application = make_app()
http_server = HTTPServer(application)
http_server.listen(options.port)
IOLoop.current().start()
来自 POSTMAN 我将 API 称为
http://127.0.0.1:8888/9cd68748-a3b5-4bc3-994d-16e921103cb2/predict
如果我没有 uuid,我只需使用正则表达式接收,如下所示
url = [(r"/(?P<id>[a-zA-Z0-9_]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/model_name/predict
匹配 url 中的名称 'model_id' 和 post 函数
@gen.coroutine
def post(self, model_id):
try:
data = tornado.escape.json_decode(self.request.body)
yield self.predict(model_id, self.db, data)
except Exception:
self.respond('server_error', 500)
并使用 url 如下
url = [(r"/(?P<model_id>[a-zA-Z0-9_.-]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/d460e889-6860-4fb4-b040-fee70c96a029.mods/predict