Description
Hello.
I've been looking into how to use ASGI applications with Azure Functions. I maintain a library called Mangum that at one point in time supported Azure Functions, but currently only supports AWS Lambda. I've received some interest in supporting multiple serverless platforms (such as Azure) again, but noticed this library now offers support for WSGI so figured I'd raise the issue here.
Would it be desirable to include support for ASGI applications in this library? This would enable a number of ASGI application frameworks to be used in a similar way to WSGI.
I migrated the removed Azure Function support from Mangum into a different project, Bonnette, which allowed using ASGI like this:
import logging
import azure.functions as func
from bonnette import Bonnette
async def app(scope, receive, send):
assert scope["type"] == "http"
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/html; charset=utf-8"]],
}
)
await send(
{"type": "http.response.body", "body": b"<html><h1>Hello, world!</h1></html>"}
)
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info("Python HTTP trigger function processed a request.")
handler = Bonnette(app)
return handler(req)
There is some incorrect behaviour in that project around the ASGI request/response handling (it is unmaintained), but maybe it can help serve as a reference for the Azure Functions. Additionally the implementation here might be helpful, there are a few AWS-specific things but mostly it handles only the HTTP->ASGI behaviour.
Anyway, I'm not using Azure Functions myself so beyond what I've mentioned above I don't have a lot of interest in supporting this externally, but still wanted to help find a solution for users of frameworks like FastAPI that have expressed interest.