我有一个原型如下所示的Flask应用程序,我希望能够重新发送在一个或多个端点中收到的一些请求。
我想存储在最新状态下发送请求所需的信息,以便可以使用相同的路径,网址方式,标题和正文重新发送。
app = Flask(__name__)
old_requests = []
@app.route("/hello", methods=["GET", "POST", "PUT", "DELETE"])
def hello():
## Do something with request data here
old_requests.append(
## some information about the request that will allow to re-send it
)
return "Ok", 200
@app.route("/resend/<int:request_index>", methods=["GET"])
def resend_request(request_index):
request_info = old_requests[request_index]
## use this info to re-send the request, with the same headers and body
return "Ok", 200
这样做的抽象和pythonic方法是什么?
在上面的代码中我存储了请求&#39;数组中的信息,但当然在真正的问题中它是一个数据库。