litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.51k stars 376 forks source link

Documentation: Add a usage example for "submounting" applications via the `asgi` handler #675

Closed provinzkraut closed 1 year ago

provinzkraut commented 2 years ago

A new user asked on our if starlite would support "submounting applications" like FastAPI does. While it is supported via the asgi handler, this usage is not apparent to new users / users who aren't too familiar with ASGI conceptually.

We should add a usage example that demonstrates how to do this.

Fund with Polar

peterschutt commented 2 years ago

Have a look at https://github.com/piccolo-orm/piccolo_admin/issues/211

provinzkraut commented 2 years ago

Oh, I actually never encountered that. Let's defer this then until #681 is resolved.

sinisaos commented 1 year ago

@provinzkraut You can use the example from Starlite Piccolo asgi template which I think is a good example of how to mount a separate asgi application.

JacobCoffee commented 1 year ago

This is doable yourself with FastAPI exports this functionality from Starlette, which itself uses https://github.com/abersheeran/a2wsgi.

@provinzkraut: FastAPI exports this functionality from Starlette, which itself uses https://github.com/abersheeran/a2wsgi You can simply use a2wsgi directly with Litestar (= The wrapped app can the simply be "mounted" using the asgi route handler: https://docs.litestar.dev/2/usage/route-handlers.html#asgi-route-handlers

ref: https://discord.com/channels/919193495116337154/1129080604328210473/1129081298238050346

Example:

from litestar import Litestar, asgi
from a2wsgi import WSGIMiddleware
from flask import Flask

flask_app = Flask(__name__)

asgi_flask_app = asgi(path="/", is_mount=True)(
    WSGIMiddleware(flask_app)
)

app = Litestar(route_handler=[asgi_flask_app])
JacobCoffee commented 1 year ago

Maybe I misunderstood the intent here - We can re-open if we want to add documentation about using a2wsgi into our docs?

provinzkraut commented 1 year ago

It was more about showing how to mount existing ASGI apps. Just an example with an explanation really.

JacobCoffee commented 1 year ago

Gotcha. my bad 😬