Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation is misleading for add_url_rule when using AsyncApp #1946

Open
fcollonval opened this issue Jul 2, 2024 · 0 comments
Open

Documentation is misleading for add_url_rule when using AsyncApp #1946

fcollonval opened this issue Jul 2, 2024 · 0 comments

Comments

@fcollonval
Copy link
Contributor

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.request 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant