Crowdhailer
Creator of Raxx
ServerSentEvent library for parsing and consuming as a Client
Push updates to web clients over HTTP, using dedicated server-push protocol.
https://github.com/CrowdHailer/server_sent_event.ex/
Server Sent Events are a way to push updates to web clients, including browsers. See the spec for more details.
This project includes the tools for manipulating, serializing and parsing Events in this format.
It can be used to build both clients and servers.
Event Client
This library now also includes an Elixir Client for an event stream.
The client behaviour defines callbacks that handle connection/disconnect/reconnect and incoming events.
A simple client that always connects could be defined as follows
defmodule AutoConnect do
@behaviour ServerSentEvent.Client
# Start connecting to the endpoint as soon as client is started.
def init(state) do
{:connect, request(state), state}
end
# The client has successfully connected, or reconnected, to the event stream.
def handle_connect(_response, state) do
{:noreply, state}
end
# Retry connecting to endpoint 1 second after a failure to connect.
def handle_connect_failure(reason, state) do
Process.sleep(1_000)
{:connect, request(state), state}
end
# Immediatly try to reconnect when the connection is lost.
def handle_disconnect(_, state) do
{:connect, request(state), state}
end
# Update the running state of the client with the id of each event as it arrives.
# This event id is used for reconnection.
def handle_event(event, state) do
IO.puts("I just got a new event: #{inspect(event)}")
%{state | last_event_id: event.id}
end
# When stop message is received this process will exit with reason :normal.
def handle_info(:stop, state) do
{:stop, :normal, state}
end
# Not a callback but helpful pattern for creating requests in several callbacks
defp request({url: url}) do
Raxx.request(:GET, url)
|> Raxx.set_header("accept", "text/event-stream")
|> Raxx.set_header("last-event-id", state.last_event_id)
end
end
# Starting the client
{:ok, pid} = AutoConnect.start_link(%{url: "http://www.example.com/events", last_event_id: "0"})
The client can also be added to a supervision tree
children = [
{AutoConnect, %{url: "http://www.example.com/events", last_event_id: "0"}}
]
Most Liked
Crowdhailer
Creator of Raxx
0.4.7 Make parsing 2_000x faster.
Just that.
See issue for benchmark and discussions.
https://github.com/CrowdHailer/server_sent_event.ex/pull/11
4
Crowdhailer
Creator of Raxx
WolfDan
Is just me, or maybe you forgot to link the project @Crowdhailer ? ^^
1
Popular in Announcing
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hi everyone,
We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
Hi,
I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
Hey everyone :waving_hand:
Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-s...
New
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components.
We also have a boi...
New
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
Other popular topics
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
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
- #code-sync
- #javascript
- #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









