All Projects → inaka → lasse

inaka / lasse

Licence: Apache-2.0 license
SSE handler for Cowboy

Programming Languages

erlang
1774 projects
HTML
75241 projects

Projects that are alternatives of or similar to lasse

erws
Erlang Websockets example using Cowboy
Stars: ✭ 43 (-2.27%)
Mutual labels:  cowboy
Turbo-Transpose
Transpose: SIMD Integer+Floating Point Compression Filter
Stars: ✭ 50 (+13.64%)
Mutual labels:  sse
restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+4.55%)
Mutual labels:  sse
neko-achievements
No description or website provided.
Stars: ✭ 16 (-63.64%)
Mutual labels:  cowboy
mu-server
A lightweight modern webserver for Java
Stars: ✭ 31 (-29.55%)
Mutual labels:  sse
redis-subscribe-sse
Stream Redis "SUBSCRIBE" or "PSUBSCRIBE" events to browsers using HTML5 Server-Sent Events (SSE)
Stars: ✭ 45 (+2.27%)
Mutual labels:  sse
prometheus-cowboy
Expose Prometheus metrics using cowboy/cowboy2
Stars: ✭ 19 (-56.82%)
Mutual labels:  cowboy
KaoYan 807
北京邮电大学软件学院考研专业课笔记(2019年)
Stars: ✭ 31 (-29.55%)
Mutual labels:  sse
simd-byte-lookup
SIMDized check which bytes are in a set
Stars: ✭ 23 (-47.73%)
Mutual labels:  sse
hasses
Hyper's Asynchronous Server Sent event (SSE) notification Server
Stars: ✭ 18 (-59.09%)
Mutual labels:  sse
sgi
Socket Gateway Interface
Stars: ✭ 16 (-63.64%)
Mutual labels:  cowboy
ternary-logic
Support for ternary logic in SSE, XOP, AVX2 and x86 programs
Stars: ✭ 21 (-52.27%)
Mutual labels:  sse
go-sse
Fully featured, spec-compliant HTML5 server-sent events library
Stars: ✭ 165 (+275%)
Mutual labels:  sse
rodeo
Test your API consuming Elixir app against a real (one-off) webserver
Stars: ✭ 15 (-65.91%)
Mutual labels:  cowboy
hpc
Learning and practice of high performance computing (CUDA, Vulkan, OpenCL, OpenMP, TBB, SSE/AVX, NEON, MPI, coroutines, etc. )
Stars: ✭ 39 (-11.36%)
Mutual labels:  sse
kastle
Kafka REST proxy
Stars: ✭ 27 (-38.64%)
Mutual labels:  cowboy
distfit
distfit is a python library for probability density fitting.
Stars: ✭ 250 (+468.18%)
Mutual labels:  sse
penguinV
Simple and fast C++ image processing library with focus on heterogeneous systems
Stars: ✭ 110 (+150%)
Mutual labels:  sse
react-native-sse
Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
Stars: ✭ 51 (+15.91%)
Mutual labels:  sse
HLML
Auto-generated maths library for C and C++ based on HLSL/Cg
Stars: ✭ 23 (-47.73%)
Mutual labels:  sse

Lasse

SSE handler for Cowboy.

References

Usage

lasse provides a cowboy loop handler called lasse_handler that describes a behaviour. To include it in your server routes, just add the following tuple to your dispatch routes:

{<<"/your/[:route]">>, lasse_handler, [your_module]}
% or
{<<"/your/[:route]">>, lasse_handler, [#{module => your_module, init_args => Args}]}

Specifying the module (e.g your_module) is mandatory while providing a value for init_args is optional.

Additionally, in your module, you have to implement the lasse_handler behaviour and its callbacks:

-behaviour(lasse_handler).

Contact Us

If you find any bugs or have a problem while using this library, please open an issue in this repo (or a pull request :)).

And you can check all of our open-source projects at inaka.github.io

Examples

You can find some example applications that implement the lasse_handler in the examples folder.

API

notify(Pid, Message) -> ok

Used to send in-band messages to the handler given its Pid.

Types:

  • Pid = pid()
  • Message = any()

Callbacks

init(LastEventId, Req) -> {ok, NewReq, State}

| {ok, NewReq, InitialEvents, State}
| {no_content, NewReq, State}
| {shutdown, StatusCode, Headers, Body, NewReq, State}

Will be called upon initialization of the handler, receiving the value of the "last-event-id" header if there is one or undefined otherwise. If everything goes well it should return {ok, NewReq, State} to leave the connection open or {ok, NewReq, InitialEvents, State} if there are any InitialEvents that need to ben sent before the handler enters its loop.

In case the handler has no content to deliver it should return {no_content, NewReq, State} and the client will receive a response with a status code 204 No Content. A custom response can be provided for other scenarios by returning {shutdown, StatusCode, Headers, Body, NewReq, State}, which will cause the handler to reply to the client with the information supplied and then terminate.

Types:

  • InitArgs = any()
  • LastEventId = binary() | undefined
  • Req = cowboy_req:req()
  • NewReq = cowboy_req:req()
  • State = any()
  • StatusCode = cowboy:http_status()
  • Headers = cowboy:http_headers()
  • Body = iodata()

handle_notify(Msg, State) -> Result

Receives and processes in-band messages sent through the lasse_handler:notify/2 function.

Types:

  • Msg = any()
  • State = any()
  • Result = result()

handle_info(Msg, State) -> Result

Receives and processes out-of-band messages sent directly to the handler's process.

Types:

  • Msg = any()
  • State = any()
  • Result = result()

handle_error(Msg, Reason, State) -> NewState

If there's a problem while sending a chunk to the client, this function will be called after which the handler will terminate.

Types:

  • Msg = any()
  • Reason = atom()
  • State = any()
  • NewState = any()

terminate(Reason, Req, State) -> ok

This function will be called before terminating the handler, its return value is ignored.

Types:

  • Reason = atom()
  • Req = cowboy:http_headers()
  • State = any()

Types

result() = {'send', Event :: event(), NewState :: any()}

| {'nosend', NewState :: any()}
| {'stop', NewState :: any()}

event() = [event_value(), ...]

The field data is required for every event returned by handle_notify() and hanfle_info(), if none is supplied data_required will be thrown.

event_value() = {'id', binary()}

| {'event', binary()}
| {'data', binary()}
| {'retry', binary()}
| {'comment', binary()}
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].