Skip to content

Documentation is misleading for add_url_rule when using AsyncApp #1946

Description

@fcollonval

Description

The typing expected by starlette route callback is:

route: typing.Callable[[Request], typing.Awaitable[Response] | Response],

https://github.com/encode/starlette/blob/6f863b0d3b8e8f18d5df9e8cd2514f7085b874e1/starlette/applications.py#L161

So the example shown in the doc (that works for flask), does not work for AsyncApp

def healthz():
    return 200

app.add_url_rule("/healthz", "healthz", healthz)

Expected behaviour

add_url_rule works the same way for Flask and AsyncApp and connexion context can be used.

Actual behaviour

Currently to make it work

from starlette.requests import Request
from starlette.responses import JSONResponse

def healthz(request: Request):
    return JSONResponse({}, 200)

Steps to reproduce

Add a custom rule using app.add_url_route

Additional info:

  • Python 3.10.13
  • Connexion: 3.0.6
  • starlette: 0.37.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PR welcomeWe would welcome and review a PR addressing this issuedocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions