Using REST API for Subscriptions

I’ve created an app using AppGyver. In this app, two users can belong to the same given group and therefore can access and manipulate the same data. At the moment, if Bob creates a new record in a table, Alice would need to send a GET request to the API to retrieve it. Of course, the problem is that Alice does not necessarily know when Bob has created a new record, so she would need to be constantly sending requests to the API to retrieve the latest data, which would be a waste of resources.

I figured this is a problem which can easily be solved using subscriptions using something like WebSockets or HTTP Streaming. However, I’m still trying to understand whether and how could I use the Publish-Subscribe Messaging REST API to solve this problem. Ideally, Alice subscribes to receive messages from the server which let her know when the data has changed, which then allows her to send a request to retrieve the data only when necessary.

However, looking a the documentation it suggests that even after subscribing to a channel, I will still need to send GET requests to retrieve messages every 60 seconds, which defeats the point of having a subscription in the first place, since I could simply send a GET request to query the table every 60 seconds.

What am I missing?

Hello @Juan_Giraldo ,

Thank you for the question. Backendless support web sockets we call it real-time database, and our sdk support it Overview - Backendless SDK for JavaScript API Documentation, but not for rest. Are you able to use JS sdk in AppGyver app? Or maybe you are able to consider using Backendless UI Builder instead?

Hi @sergey.kuk,

Thank you for your answer! Unfortunately AppGyver doesn’t yet allow for integration with third-party libraries (a massive flaw in my opinion), therefore I wouldn’t be able to use the JS SDK.

Regarding UI Builder, I had already found out about AppGyver and started building out the front-end using their Composer tool by the time I came across Backendless, therefore switching would probably be too costly at this point, although we could consider it in the future.

Out of curiosity, in what scenarios is the Publish-Subscribe REST API recommended for?

You can publish messages using REST API and you can retrieve messages with the polling (or on-demand retrieval) strategy.

Regards,
Mark

1 Like