Immutable Request
Combines superagent
, bluebird
, immutable
and lru-cache
for sane isomorphic HTTP POST/GET abstraction.
Example
// Simply use the static factoryRequest; // send a POST request with { seed: 1337 } as its form bodyconst post = Request;// nevermind, abort itpost; // you can specify timeout (in ms) and// return type ('immutable', 'json', 'object' or 'null')Request; // leverage automatic, clever userland cachingconst requester = 'http://localhost:8888' max: 100 // cache no more than 100 HTTP requests maxAge: 60000 // cache expires after 60s timeout: 10000 // request timeout after 10000; requester;// cache is done by full path, so querystring can be used to force recachingrequester;// POST requests are not cached, the request is sent twicerequester;requester;// cancel all pending requestsrequester;// clear the cache and destroy referencesrequester;
Usage
This module is written in ES6/7. You will need babel
to use it.