Gallop
Gallop polls REST APIs at particular intervals to listen for changes.
Installation
Gallop is available on the NPM registry.
npm install gallop
Usage
var gallop = interval: 10; // Add a target.gallop // Start listening.gallopstart;
Documentation
Gallop
Requiring Gallop exposes a Gallop constructor. This object serves as a daemon which listens to requests in the background. Arguments:
options
-- An optional options object with keys:interval
-- The polling interval in milliseconds. Defaults to 1 minute.
var Gallop = ; var daemon = interval: 500;
Creating targets
A Gallop daemon subscribes to targets, which are composed of a REST API URL, an options object for the request, and a callback that fires whenever the response from that API endpoint changes. Arguments:
url
-- A string endpoint URLoptions
-- An options object for the request -- see documentation for Restler's optionscallback
-- A callback that takeserr
,result
, andhttpResponse
to be called whenever the data changes
daemon;
subscribe
returns a target ID, which can be passed to unsubscribe
to remove the target.
// Save the target ID.var id = daemon; // Unsubscribe from the target.daemon;
Listening for changes
The Gallop daemon can start
and stop
; stopping in the middle of the polling cycle will complete the current cycle.
daemonstart; // Some time later...daemon;
License
© 2013 Lehao Zhang. Released under the terms of the MIT license.