def asgi_app(
    label: Optional[str] = None,  # Label for created endpoint. Final subdomain will be <workspace>--<label>
    wait_for_response: bool = True,  # Whether requests should wait for and return the function response.
) -> Callable[[Callable[..., Any]], _PartialFunction]:

Register an ASGI app with this application.

Asynchronous Server Gateway Interface (ASGI) is a standard for Python synchronous and asynchronous apps, supported by all popular Python web libraries. This is an advanced decorator that gives full flexibility in defining one or more web endpoints on Modal.

To learn how to use Modal with popular web frameworks, see the guide on web endpoints.

The two wait_for_response modes for webhooks are as follows:

  • wait_for_response=True - tries to fulfill the request on the original URL, but returns a 302 redirect after ~150s to a result URL (original URL with an added __modal_function_id=fc-1234abcd query parameter)
  • wait_for_response=False - immediately returns a 202 ACCEPTED response with a JSON payload: {"result_url": "..."} containing the result “redirect” url from above (which in turn redirects to itself every 150s)