I started exploring Phoenix for one thing only: Channels (or actually fast real time communication over websockets). In this post I explore how to use them (yes this is a follow up of My first Phoenix-app-post).
Websockets don’t pass session cookies. Because we don't have access to these we need to transfer the user's identity in a different way. One of the recommendations I found was passing a user_token
using a ``-tag (adjusting templates/layout/app.html.eex
):
We can access this with a simple query selector in javascript:
document.querySelector("meta[name=user_token]").content
But that’s for later. Let’s move to the server side, since we need something to connect to, a Socket.
In our default project there is alrea…
Some time ago I actually initiated my very first Phoenix app, but was a bit disappointed by the lack of a rich box of gems (like that of ruby's) and/or I didn't have the time to invest heavily in researching all the possibilities. One of my new year resolution was to actively pursue more knowledge, hence I'm giving it a second shot.
I'm a full-stack Rails developer, but I needed real time messaging. That is not something Rails is typically good at (although it works), but Elixir (with its Erlang base) is well known for, even in the ruby community. Phoenix wraps Elixir in a nice Rails-like package ready for web and API development.
brew install elixir
) and make sure you have [node.js](https://nodejs.or…Dit artikel van murblog van Maarten Brouwers (murb) is in licentie gegeven volgens een Creative Commons Naamsvermelding 3.0 Nederland licentie .