Sometimes it's unavoidable. The only way to get updates from that web service you love is to nag at it, endlessly repeating the same HTTP request like a child who's grown tired of the car ride. Polliwog manages the details so that you can focus on the data.
- Transforms a URL into an EventEmitter stream of data events.
- Cache-hint awareness means fewer unnecessary HTTP requests by default.
- Response de-duplication keeps your application from re-processing the same data over and over again.
There's no better way to explain Polliwog than with an example.
const url = 'http://date.jsontest.com'
const options = { json: true }
const p = new Polliwog(url, options)
p.on('response', console.log)
p.start()
The Polliwog constructor takes two arguments, he HTTP or HTTPS URL to poll, and an optional hash of configuration options.
The following configuration options are supported.
Specifies the polling interval, in milliseconds.
When true
, response bodies will be parsed as JSON.
When true
, events will be fired following every request (rather than when data
has changed).
When true
, locally cached data will always be considered expired. Note that
on its own, this will still result in conditional requests based on the Etag
and Last-Modified
headers being made.
When true
, Etags will not be considered when testing cache validity.
When true
, the Last-Modified date will not be considered when testing cache
validity.
Produces a stream of HTTP responses, regardless of HTTP status code.
Produces a stream of successful HTTP responses (2xx
).
Produces a stream of unsuccessful HTTP responses (4xx
and 5xx
).
Produces a stream of exceptions, from networking failures to JSON parsing errors.
Constructs a new poller for the specified URL. See Configuration for a list of the supported options.
Registers a new callback for the named event. See Events for a list of the supported events.
Unregisters a callback from the named event.
Begins polling the URL for data and firing the appropriate events.
Terminates the current polling cycle and aborts any further data processing. Events for any outstanding requests may still be fired after this method is called.