ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

Methodless Routes #130

Closed ZeroIntensity closed 5 months ago

ZeroIntensity commented 5 months ago

Feature description

Flask (at least when I used it) had a bare route method that would accept all methods. This could work especially nicely now that #95 has been merged.

Feature example API

from view import new_app, Context

app = new_app()

@app.route("/")
async def index(ctx: Context):
    return f"you called this route with the {ctx.method} method"

app.run()

Anything else?

No response

ZeroIntensity commented 5 months ago

This could also have the methods parameter, like so:

from view import new_app, Context

app = new_app()

@app.route("/", methods=("GET", "POST"))
async def index(ctx: Context):
    return f"you called this route with the {ctx.method} method"

app.run()