Issue
we are building REST service with python Flask, and as it is usually in large projects, our controller methods getting longer and longer, that make really hard to track, which parameters are used / expected from a POST request's body.
So I'm looking such a solution, where I could declare the controller method
@dataclass
class MyPOSTBodyDataClass:
...
@mod_formula_bp.route('/add/<id>', methods=['POST'])
@login_required
def add(id, post_body: MyPOSTBodyDataClass):
...
So in that case I don't call request.json["property_x"]
or similar.
Is it possible to implement in Flask?
Note I have heard about the parameter validator, but I think, I'm looking to a slightly different solution
Solution
You can use Flask-Pydantic
to validate by MyPOSTBodyDataClass. More info: https://github.com/bauerji/flask-pydantic
Answered By - TanThien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.