你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

AsgiMiddleware Class

This middleware is to adapt an ASGI supported Python server framework into Azure Functions. It can be used by either calling the .handle() function or exposing the .main property in a HttpTrigger.

Instantiate an ASGI middleware to convert Azure Functions HTTP request into ASGI Python object. Example on handling ASGI app in a HTTP trigger by overwriting the .main() method:

import azure.functions as func

from FastapiApp import app

main = func.AsgiMiddleware(app).main

Inheritance
builtins.object
AsgiMiddleware

Constructor

AsgiMiddleware(app)

Parameters

Name Description
app
Required

Methods

handle

Deprecated. Please use handle_async instead:

import azure.functions as func

from FastapiApp import app

async def main(req, context): return await func.AsgiMiddleware(app).handle_async(req, context)

handle_async

Method to convert an Azure Functions HTTP request into a ASGI Python object. Example on handling ASGI app in a HTTP trigger by calling .handle_async() in .main() method:

import azure.functions as func

from FastapiApp import app

async def main(req, context): return await func.AsgiMiddleware(app).handle_async(req, context)

notify_shutdown

Notify the ASGI app that the server is shutting down.

notify_startup

Notify the ASGI app that the server has started.

handle

Deprecated. Please use handle_async instead:

import azure.functions as func

from FastapiApp import app

async def main(req, context): return await func.AsgiMiddleware(app).handle_async(req, context)

handle(req: HttpRequest, context: Context | None = None)

Parameters

Name Description
req
Required
context
Required
Default value: None

handle_async

Method to convert an Azure Functions HTTP request into a ASGI Python object. Example on handling ASGI app in a HTTP trigger by calling .handle_async() in .main() method:

import azure.functions as func

from FastapiApp import app

async def main(req, context): return await func.AsgiMiddleware(app).handle_async(req, context)

async handle_async(req: HttpRequest, context: Context | None = None)

Parameters

Name Description
req
Required
context
Required
Default value: None

notify_shutdown

Notify the ASGI app that the server is shutting down.

async notify_shutdown()

notify_startup

Notify the ASGI app that the server has started.

async notify_startup()