All Projects → CrowdHailer → server_sent_event.ex

CrowdHailer / server_sent_event.ex

Licence: Apache-2.0 License
Push updates to Web clients over HTTP or using dedicated server-push protocol

Programming Languages

elixir
2628 projects

ServerSentEvent

Hex pm Build Status License

Push updates to web clients over HTTP, using dedicated server-push protocol.

Server Sent Event Standard

https://html.spec.whatwg.org/#server-sent-events

Usage

Parsing and Serializing

iex(1)> event = ServerSentEvent.new("my data")
%ServerSentEvent{
  comments: [],
  id: nil,
  lines: ["my data"],
  retry: nil,
  type: nil
}

iex(2)> binary = ServerSentEvent.serialize(event)
"data: my data\n\n"

iex(3)> {:ok, {^event, ""}} = ServerSentEvent.parse(binary)
{:ok,
 {%ServerSentEvent{
    comments: [],
    id: nil,
    lines: ["my data"],
    retry: nil,
    type: nil
  }, ""}}

Client

This project also includes a general purpose client. See documentation for ServerSentEvent.Client for more information.

Testing

git clone [email protected]:CrowdHailer/server_sent_event.ex.git
cd server_sent_event.ex

mix deps.get
mix test
mix dialyzer

Benchmarks

Some microbenchmarks have been written to inform some implementation decisions

To run them, run

mix run bench/*
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].