andarotajo
How do I build a WebSocket client library?
Hello, I’m very new to Elixir and looking to get started on a little project I’m interested in. Inspired by this blog post I’d like to build a “simple” client library giving users a simpler way to use Home Assistant’s WebSocket API.
I think a library like this give users the most flexibility in how they write automations and keeps the project scope limited for my own sanity ![]()
But since Elixir and writing libraries in general are very new to me, I’d love to get some pointers on how to go about that. Things I’ve been wondering:
- I thought about building the library around callbacks, e.g. a callback for Home Assistant’s state changes, allowing the user to pattern match what they need. How do I build a WebSocket client around this concept
- Is using a GenServer the way to go? I’d need to keep a state
- Besides the URL there’s also a token I’d need to connect to Home Assistant. Is there a “best practice” on how to configure stuff like this?
Some good libraries I can use as guidance for code quality and stuff would probably help if you’ve got some suggestions.
For reference, this is Home Assistant’s WebSocket API
Thank you very much for helping!
Most Liked
jstimps
I like to use gun for client-side ws work. A while ago I wrote a little Livebook example to remind my future self of the function calls involved.
bbangert
I recently extracted a websocket lib for HA that I published on hex: Hassock — hassock v0.1.3
This uses the newer HA command that uses diff’s for efficiency with an optional ETS cache for faster queries without sending everything over the websocket connection.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








