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

Django Channels HTTP support extend documentation #2026

Open
Tomislav-Zoricic opened this issue Jul 6, 2023 · 2 comments
Open

Django Channels HTTP support extend documentation #2026

Tomislav-Zoricic opened this issue Jul 6, 2023 · 2 comments

Comments

@Tomislav-Zoricic
Copy link

Tomislav-Zoricic commented Jul 6, 2023

I am interested in using Channels to support both my HTTP async requests, as well as websockets.

There are millions tutorials out there on how to implement websocket, and that part is very clear to me.

Things change when it comes to implementing HTTP async requests using Channels.

The only example given in the documentation is to set http to django_asgi_app.
I can't find anywhere how to set urlpatterns to the http protocol mentioned, or how attach any routes to be handled through asgi http protocol.

I see that there is such thing as AsyncHttpConsumer however once again, I can't find a way to connect it to the url that I could connect with http protocol.

Would you mind adding an example to documentation of how to use async http with channels, not just websockets?

Thanks a million!

@sithembiso
Copy link

I am also looking for this and I've been struggling for two days now. Here's a Stackoverflow thread in case it yields any relevant results in future.
https://stackoverflow.com/questions/76997708/django-setting-up-server-sent-events-with-channels-unhandled-exception-sseco

@runekaagaard
Copy link

Hi @Tomislav-Zoricic. To enable "normal" http routes with channels, you only need to have this in asgi.py:

django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter({
    # All the normal urls defined in myproject/urls.py are now available
    "http": django_asgi_app,
})

And then you need to have "daphne" as the first app in INSTALLED_APPS. Notice daphne takes over the runserver command so it looks like this:

Starting ASGI/Daphne version 4.0.0 development server at http://127.0.0.1:8000/

God speed! <3

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

4 participants
@runekaagaard @sithembiso @Tomislav-Zoricic and others