问题
Im looking to make my Flask based API case insensitive for all incoming payloads. rather than having to apply this to all api-route functions i want to apply this to the @app.before_request
decorator, such that for all incoming requests with json payloads (POSTs and PUTs) I directly edit the payload before it is handled by the applicable app.route
function.
POST {"x":1, "Y":2}
Should be formatted to POST {"x":1, "y":2}
for request endpoints, but I can't seem to make this happen.
@app.before_request
def before_request():
if request.json:
data = RecusivelyLowerKeys(request.get_json())
request.data = json.dumps(ldata)
so far this approach hasn't worked and the original request payload seems static.
Any tips or alternative approaches would be appreciated thanks.
来源:https://stackoverflow.com/questions/44587404/edit-incoming-request-body-payloads-in-flask-api