目前,我们将该呼叫代理到另一项服务。为此,我们检查request.method
是GET
,我们使用request.get(url)
,如果request.method
是POST
,我们使用request.post(url)
。是否有更清洁的实现来处理这种用法?
@app.route('/<path:url>', methods=('GET', 'POST'))
def foo(url):
if check_token():
req_url = "http://localhost:8081/{}?{}".format(url, request.query_string.decode('utf-8'))
if request.method == 'GET':
req = requests.get(req_url, stream=True)
elif request.method == 'POST':
req = requests.post(req_url, stream=True)
答案 0 :(得分:0)
您可以使用两种不同的方法实现这两个调用。每种方法都应该只允许一种方法。
Array
(
[0] => Array
(
[id] => 1
[code] => asq12d134
[mail] => info@localhost
[date] => 2017-01-18
)
[1] => Array
(
[id] => 2
[code] => 1qeacetq
[mail] =>info@localhost
[date] => 2017-01-18
)
[2] => Array
(
[id] => 3
[code] => awq12sq
[mail] =>info@localhost
[date] => 2017-01-18
)
)