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

"Extension" : channels for Real-time API backend. #205

Open
ndrean opened this issue Oct 9, 2023 · 1 comment
Open

"Extension" : channels for Real-time API backend. #205

ndrean opened this issue Oct 9, 2023 · 1 comment

Comments

@ndrean
Copy link

ndrean commented Oct 9, 2023

This video is interesting. It explains how you can build - mimic - a Phoenix REST API backend using WS-Channels (stateful) .

Instead of running a one shot HTTP requests (eg the client makes a fetch in JS to the Phoenix API endpoints), the client will establish a websocket, and run a channel.push("endpoint:event", msg). Thanks to pattern matching, the server handles this in somehandle_in("endpoint:event", data, socket) and can broadcast back a response. Thanks to pattern matching, we have a correct routing of the action. This imitates a REST api but the connection is bi-directional, "pseudo-real-time" and stateful.

Note: to communicate from the server but outside of the channel module, you can broadcast on a topic to which the channel subscribed, or use the Registry (cf https://elixirschool.com/blog/live-view-with-channels), and the channel will receive it in a handle_info. Form there, you can push to the client.

The story around the parsing is not completely clear.

A refreshing refresher on Channels by Brooklin Myers

This guy wrote this package channel_handler. To try!

https://www.youtube.com/watch?v=ZBG9VXTycpI

@ndrean ndrean changed the title "Deviation" : channels for Real-time API backend. "Extension" : channels for Real-time API backend. Oct 9, 2023
@nelsonic
Copy link
Member

nelsonic commented Nov 7, 2023

@ndrean thanks as always for sharing interesting things. ❤️

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

2 participants