Streambin

Create server-sent event streams with ease.

What?

Ever felt the need to add some interactivity to your prototype? Needed an event stream to communicate where a direct peer-to-peer connection is not possible? Or just wanted to explore how those server-sent events work?

Without setting up a server somewhere?

Well, then Streambin is for you!

Why?

I just love http server-sent events. And I use them heavily to connect different personal services or devices. Instead of writing server-sent event stream servers again and again, I created a service that makes the generation and interaction with server-sent event streams effortless.

How?

You can create an event stream by creating a persistent http connection (which also acts as an event stream). The streams are ephemeral and only exist as long as you keep this connection open. Also: no data is stored anywhere within Streambin.

Let's create a stream:

# -N prevents curl from buffering 
  # not required to host a stream, but irritating if events don't show up immediately            
  $ curl -N https://streambin.pbedat.de/streams/<your-stream-name>
  event: init
  data: abcd123-123123123123-abcd-123123213

The first event 'init' tells you that everything is fine and your stream is ready to use. The payload is the streams 'token' and used to bring a little bit of optional security into the fold.

Note that the connection to this 'control stream' is exclusive. Further requests to this URL will result in a 429 Too Many Requests error

Subscribe to your stream:

$ curl -N https://streambin.pbedat.de/streams/<your-stream-name>/out;
          event: init
          data: hello

Listening to this endpoint is not exclusive. This is where your published events will show up!

Publish events:

$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{ "type": "my-event", "data": "this is the events payload"}' \
http://127.0.0.1:8989/streams/<your-stream-name>/in

After you have published the event it will show up in your event stream:

$ curl -N https://streambin.pbedat.de/streams/<your-stream-name>/out;
event: init
data: hello

event: my-event
data: this is the events payload

Api

Endpoint Description
GET https://streambin.pbedat.de/streams/:name?access
Accept: text/event-stream

Creates a new stream named :name

(optional) access defines wether the stream should be secured. The default value READ_WRITE allows unhindered access to the stream. Setting the access to READ will require the token, provided by the init event, to publish events to the stream.

  • 200 stream created successfully
  • 429 the stream was already created and currently open
GET https://streambin.pbedat.de/streams/:name/out

Listens to the stream

  • 200 successfully connected to the stream
POST https://streambin.pbedat.de/streams/:name/in Authorization: Bearer <token>(optional)

Publishes events to the stream

  • 200 event published successfully
  • 401 the stream is secured by ?access=READ and requires the streams token as bearer token

Demo

Chat

This chat is completely stateless (nothing will be saved) and built solely upon streambin.

Made with 💖 by @pbedat