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!
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.
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.