Created
November 7, 2022 11:31
-
-
Save keuv-grvl/4926fd8016cc13eebb64b5c023dd3900 to your computer and use it in GitHub Desktop.
Add helpers to Flask to mimic fastapi decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fast_flask import Flask | |
app = Flask(__name__) | |
@app.get("/users/") # equivalent to `@app.route("/users/")` from flask.Flask | |
def get_user_details(user_id: int = 123): | |
return {"123": "bob"} | |
if __name__ == "__main__": | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flask | |
class Flask(flask.Flask): | |
def get(self, rule: str): | |
return super().route(rule=rule, methods=["GET"]) | |
def post(self, rule: str): | |
return super().route(rule=rule, methods=["POST"]) | |
def patch(self, rule: str): | |
return super().route(rule=rule, methods=["PATCH"]) | |
def delete(self, rule: str): | |
return super().route(rule=rule, methods=["DELETE"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment