-
-
Notifications
You must be signed in to change notification settings - Fork 930
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
Implement CBV pattern #35
Conversation
starlette/decorators.py
Outdated
from starlette.types import ASGIInstance, Receive, Send, Scope | ||
|
||
|
||
def asgi_application(func): | ||
def make_asgi(func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kinda thinking that we'll drop the asgi_application
/make_asgi
decorator altogether - I think it just muddies things up.
Let's leave this alone for now, but perhaps don't use it in the PR, and include any logic directly in the class.
starlette/views.py
Outdated
def as_view(cls) -> ASGIApp: | ||
def view(scope: Scope): | ||
self = cls() | ||
return self.dispatch(scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do the same closure .as_view()
dance that Django does?
Rather than using .as_view()
I figure that we just implement the endpoint/view/whatever class as an ASGI application. We're not using multi-threading so I don't think we need the same "put stuff in a closure for safety" dance, but maybe I'm not thinking it through enough.
I made some changes based on your comments - removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d also suggest we drop support for the handler methods being non-awaitable. Let’s just cover async stuff in Starlette.
…e method, tests, documentation
I've made the following updates to this PR:
|
Coolio! One observation: We’ll want to make sure that each request gets a new instance, rather than routing to an instance of the class. Also, use 406 for the method-does-not-exist-on-this-class case. Good stuff! |
Added some further commits on top of this, in #52. Thanks so much for this! |
hi @tomchristie can this be also added to the docs ... i found only this here |
@delijati that was the case before the doc changed 0.12.0...master |
@foxmask @delijati https://www.starlette.io/endpoints/ (Or are we talking about something else?) |
@tomchristie if that were endpoints here edit the pasted URL does not work fine so ... I wanted to show you : then > "file changed" then we can see the docs/index.md |
We're not documenting a pure ASGI class, nope. We don't really need to in ASGI 3, since it's easier to write them as plain functions. What we are documenting is the class-based |
Refs #27
This is an attempt to define a CBV pattern in Starlette.
Example usage: