Edit incoming request body payloads in flask api

与世无争的帅哥 提交于 2021-01-28 05:52:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!