dmartinez
dmartinez

Reputation: 287

Check RESTful service automatically, without a call?

Imagine the scenario: You have a database that is queried/updated by more then 1 app, and you also have a RESTful service that uses the database.

Is it possible to, somehow, inform the client (web-page, or whatever) that the database has new data without calling the web-service every second to look for new data?

This question is more in a sense of "reactive" calls, just like RMI methodology works.

I might be dreaming, but there must be a way to do so without having an AJAX call every XX seconds.

PS. if the AJAX call is really necessary, is there a better/smarter way of doing that ?

Sorry if the question is too silly.

I do appreciate your time.

Upvotes: 2

Views: 63

Answers (2)

Pedro Werneck
Pedro Werneck

Reputation: 41928

If that service is really RESTful, and not just using REST as a buzzword, then I guess the most straightforward way to do that would be a resource that you poll constantly with an If-Modified-Since header. That response should be in a cache somewhere, the clients should get it from there, and the cache should be reset when there's new data.

On the other hand, if you're not really concerned with the REST constraints, then you can follow Kristian's response and use some kind of notification, through a message queue, pub-sub , etc.

A compromise between the two is having a notification only telling the clients that the server has new data, not sending it on the notification. That's probably how I'd do it.

Upvotes: 0

Kristian
Kristian

Reputation: 21830

this "reactive" thing you're talking about is aka "event-driven" webservices (you can accomplish that by using node.js, for example). the event updates usually get served via a "message queue" that multiple consumers listen to for updates, and react accordingly.

in particular, the act of listening for these updates in a message queue typically is done via the publisher subscriber design pattern. which is pretty popular these days and is even getting included into some newer databases.

Check out Redis DB's pub sub feature as an example.

Upvotes: 1

Related Questions