ZeroIntensity / view.py

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

Defer ASGI #149

Open ZeroIntensity opened 8 months ago

ZeroIntensity commented 8 months ago

Feature description

For compatibility with ASGI toolkits like Starlette, view.py should make it possible to defer the ASGI scope, receive, and send. This will allow someone to for example, mount an existing Starlette app against a view.py server, which very much aligns with batteries-detachable.

Feature example API

from starlette.responses import PlainTextResponse
from view import new_app

app = new_app()

@app.defer("/prefix")
async def starlette_app(scope, receive, send):
    assert scope['type'] == 'http'
    response = PlainTextResponse('Hello, world!')
    await response(scope, receive, send)

app.run()

Anything else?

This will be waiting on #82, as prefixing will require path parameters.

ZeroIntensity commented 4 months ago

Maybe this could some with some WSGI hook utility as well? I don't know that much about WSGI, but theoretically it should be possible to convert ASGI objects into their WSGI counterparts. This would be incredibly useful for say, mounting a Django app on top of a view.py app.