Beta-testing Spark.publish / Server-Sent Events - I'd Volunteer!

:spark: Team - I’d be quite willing to beta-test Spark.publish() and the Server-Sent Events setup if you can let me have the event source URL :smile:

Been reading up on the material @zachary mentioned in another post (copied below), and am very excited about this new functionality.

http://www.html5rocks.com/en/tutorials/eventsource/basics/5


http://dev.w3.org/html5/eventsource/2

1 Like

Thanks @binaryfrost! I will update the docs with the event source URLs today, but they won’t work. It’s a pretty complex addition to the whole Cloud infrastructure. As soon as there’s something to meaningfully test, we’ll let you know! :+1:

EDIT: Forgot I already added a summary to the top of the API docs, just haven’t added the detail in the events section below yet.

And I just added the detailed description of the event source URLs:
http://docs.spark.io/#/api/reading-data-from-a-core-events

As I said, they won’t work anytime soon, but you could get your test code ready with these URLs.

@zachary
Is the intent for this to be used by browsers?
Are you trying to cover backend systems subscribing to these events?

I’d like my web service to be able to handle publish events. I’m not sure how to go about planning this with the SSE implementation.

Any ideas?

Hi Kareem,

One of the links in the section of the documentation I linked to will describe it all to you. You can write javascript in the browser to subscribe to an EventSource. From there you can add an event listener for new messages. Here’s an example that uses jQuery to append an item to a list.

var source = new EventSource(
  'https://api.spark.io/v1/devices/events' +
  '?access_token= 38bb7b318cc6898c80317decb34525844bc9db55');
source.addEventListener('message', function(e){
  $('#events-list').append('<li>' + e + </li>');
});

For back-end services, an SSE stream is just a normal HTTP request that stays open, so whatever library you are currently using for making the other API requests should work fine. You will just have to handle the data differently since the connection does not close.

1 Like