https://github.com/crowdhailer/server_sent_event.ex
Push updates to Web clients over HTTP or using dedicated server-push protocol
https://github.com/crowdhailer/server_sent_event.ex
Last synced: 9 months ago
JSON representation
Push updates to Web clients over HTTP or using dedicated server-push protocol
- Host: GitHub
- URL: https://github.com/crowdhailer/server_sent_event.ex
- Owner: CrowdHailer
- License: apache-2.0
- Created: 2017-08-19T06:49:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-13T12:23:24.000Z (about 1 year ago)
- Last Synced: 2025-04-09T20:09:28.962Z (9 months ago)
- Language: Elixir
- Homepage: https://hex.pm/packages/server_sent_event
- Size: 61.5 KB
- Stars: 21
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ServerSentEvent
[](https://hex.pm/packages/server_sent_event)
[](https://travis-ci.org/CrowdHailer/server_sent_event.ex)
[](LICENSE)
**Push updates to web clients over HTTP, using dedicated server-push protocol.**
- [Install from Hex](https://hex.pm/packages/server_sent_event)
- [Documentation available on hexdoc](https://hexdocs.pm/server_sent_event)
### Server Sent Event Standard
https://html.spec.whatwg.org/#server-sent-events
## Usage
### Parsing and Serializing
```elixir
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 git@github.com: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/*