Integrations
ASGI 3.0
Component: asgi3
(ASGIComponent
)
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/asgi3
This is a generic integration for ASGI 3.0 applications.
Resources available on the global context:
the application object
name:
default
Resources available to request handlers:
the ASGI scope of the request
type: asgiref.typing.HTTPScope or asgiref.typing.WebSocketScope
name:
default
Django
Component: django
(DjangoComponent
)
Requires manual insertion of the asphalt.web.django.AsphaltMiddleware
middleware
to the MIDDLEWARE
list in settings.py
for resource injection to work.
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/django
This integration is based on the ASGI 3.0 integration.
Resources available on the global context:
the application object
type: asgiref.typing.ASGI3Application or django.core.handlers.asgi.ASGIHandler
name:
default
Resources available to request handlers:
the ASGI scope of the request
type: asgiref.typing.HTTPScope
name:
default
the request object
type: django.http.HttpRequest
name:
default
Note
Websocket support via Django Channels has not been implemented.
Starlette
Component: starlette
(StarletteComponent
)
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/starlette
This integration is based on the ASGI 3.0 integration.
Resources available on the global context:
the application object
type: asgiref.typing.ASGI3Application or starlette.applications.Starlette
name:
default
Resources available to HTTP request handlers:
the ASGI scope of the request
type: asgiref.typing.HTTPScope
name:
default
the request object
name:
default
Resources available to websocket handlers:
the ASGI scope of the request
name:
default
FastAPI
Component: fastapi
(FastAPIComponent
)
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/fastapi
This integration is based on the ASGI 3.0 integration.
FastAPI has its own dependency injection system which means Asphalt resources must be
injected a bit differently in FastAPI endpoints. Instead of using
Depends()
as the default value for a resource parameter you wish to
inject, you need to use AsphaltDepends()
instead. The
machinery in FastAPIComponent
will handle the appropriate
translation.
Resources available on the global context:
the application object
name:
default
Resources available to HTTP request handlers:
the ASGI scope of the request
type: asgiref.typing.HTTPScope
name:
default
the request object
name:
default
Resources available to websocket handlers:
the ASGI scope of the request
name:
default
Litestar
Component: litestar
(LitestarComponent
)
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/litestar
This integration is based on the ASGI 3.0 integration.
Litestar has its own dependency injection system which can optionally be used to inject
Asphalt resources in web endpoints. This can be done by using
AsphaltProvide
instead of Provide
:
from litestar import get
from asphalt.web.litestar import AsphaltProvide
@get("/endpointname", dependencies={"myresource": AsphaltProvide(SomeConnection)})
async def myendpoint(myresource: SomeConnection) -> None:
...
This would be roughly equivalent to:
from litestar import get
from asphalt.core import require_resource
@get("/endpointname")
async def myendpoint() -> None:
myresource = require_resource(SomeConnection)
...
Resources available on the global context:
the application object
name:
default
Resources available to HTTP request handlers:
the ASGI scope of the request
type: asgiref.typing.HTTPScope
name:
default
the request object
type: litestar.Request
name:
default
Note
The request resource is created from the ASGI scope object by the Asphalt middleware, and does NOT share state with any request object provided by the Litestar framework
Resources available to websocket handlers:
the ASGI scope of the request
name:
default
AIOHTTP
Component: aiohttp
(AIOHTTPComponent
)
Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/aiohttp
Unlike the other frameworks supported here, AIOHTTP is not based on the ASGI standard.
Resources available on the global context:
the application object
name:
default
Resources available to request handlers:
the request object
name:
default