REST push subscriptions

Has anyone used the REST subscriptions? I’m trying to write some Java Script to use the REST API and I can’t seem to figure out how to use the subscription option with the REST API. Any help is appreciated.

Thanks!

Do you mean for instance listening to item updates using Server-sent Events (SSE)?

If so, I created a JavaScript library that uses SSE for showing Grafana panels using the state of Eclipse SmartHome items. The SmartHomeSubscriber in this library is based on how Basic UI handles SSE.

Thanks for the example, that is what I’m looking to do. It’s a little over my head right now since I’m still learning Javascript but I’m hoping I can dig through it and get some understanding of how it all works. I’m basically just looking for a way to subscribe to changes to the /rest/events updates and parse them. So I’m gonna keep digging through your example and the HABpanel code and try to put together what’s happening.

I think where my understanding is limited right now is that I don’t know how to subscribe to things like that in JavaScript yet, so that’s where I need to learn. Is there a term I can search for on Google that would help me learn these things or become a better JavaScript programmer? I’ve learned quote a lot but there are still some symbols and things I don’t quite understand what they mean.

Thanks again!

I always end up at the Mozilla Developer Network where there is lots of JavaScript (HTML, CSS) information and references. :slight_smile:

If you just want to receive all events I think subscribing to /rest/events (what HABpanel and Paper UI do) is better then subscribing to the sitemap events /rest/sitemaps/events/subscribe (what Basic UI and my library do).

In JavaScript you can use the EventSource to subscribe to these SSE events.

1 Like

Great! I will look at those resources. Thanks for all the help!