Contained herein is the source code that I demoed at my ElixirConf 2023 talk, “Conversational Web APIs”.
You can view the talk on YouTube and it is described thusly:
Phoenix Channels are great! They’re a go-to solution for adding real-time capabilities to our apps. But with a bit of creative thinking, Channels can also provide a full-duplex alternative to web API models like REST and GraphQL. Come and learn how building a stateful, Channels-based web interface can reduce network traffic, eliminate data overhead, and provide a unified mechanism for establishing application connectivity to browsers, mobile apps, and hardware devices.
After a brief introduction to (or perhaps a refresher on) Phoenix Channels, we’ll discover the interesting possibilities they represent and the problems they solve when backing a web API. You’ll learn how GridPoint leveraged Channels to build and deploy a “conversational” web API to support a critical business case, get the inside scoop on the tradeoffs involved, and learn why this model might fit your project well.
Stick around until the end for an introduction to a new Elixir library that can help jump-start your explorations with a Channel-based web API.
You might notice, upon cursory inspection, that it seems as though I’ve (perhaps unceremoniously), jammed the code for four separate projects into a single Git repository. Well, you’re right. I did that. But there was a small ceremony. Let’s just call it a monorepo.
The counter
project is a Phoenix app that powered the audience participation bit of the talk. I know some of you in the audience were just jamming on that button—you know who you are!
To run it, mix setup
and then mix phx.server
. You’ll need Elixir.
The counter-client
project is a Electron app that I used to display the audience count average on screen.
To run it, npm i
and then npm start
. You’ll need Node.js.
The lyrical
project is a simple implementation of the songs app I used as an example.
To run it, mix setup
and then mix phx.server
. You’ll need Elixir and PostgreSQL. Check out the seeds file to set up your some songs.
The lyrical-app
project is a React Native app that talks to lyrical
. I demoed this app in the iPhone simulator at the end of the talk.
To run it, npm i
and then npm start
. You’ll need Node.js and an iOS or Android dev setup.
- “Routing patterns for manageable Phoenix Channels” by Lucas San Román is the blog post I mentioned
- ChannelHandler is the great Channels routing library I mentioned
- The
LyricalWeb.Channels.Dispatcher
module defines some example routing macros
This code is licensed under the MIT license.