Skip to content

Instantly share code, notes, and snippets.

@keuv-grvl
Created November 7, 2022 11:31
Show Gist options
  • Save keuv-grvl/4926fd8016cc13eebb64b5c023dd3900 to your computer and use it in GitHub Desktop.
Save keuv-grvl/4926fd8016cc13eebb64b5c023dd3900 to your computer and use it in GitHub Desktop.
Add helpers to Flask to mimic fastapi decorators
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()
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