ZeroIntensity / view.py

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

Request Data #95

Closed ZeroIntensity closed 5 months ago

ZeroIntensity commented 7 months ago

Feature description

View does not currently support accessing values from headers, which is a pretty key feature in most web frameworks. This is going to be somewhat difficult because the data (likely some sort of object) has to be instantiated from the C API. My current idea for this implementation is design a special third type of route input that is strictly used for taking in a Context which holds all sorts of data.

Feature example API

@app.get("/")
@context
async def index(ctx: Context):
    print(ctx.cookies, ctx.headers)
    return "..."

The automatic input API could also come in handy here:

@app.get("/")
async def index(ctx: Context):
    ...

Anything else?

No response

ZeroIntensity commented 5 months ago

Could also work with the route input API, like so:

from view import new_app, headers

app = new_app()

@app.get("/")
@headers
async def index(hdrs: dict[str, str]):
    return hdrs["User-Agent"]

app.run()