This is a wrapper around
request to offer a Fluture API (instead of callback- or promise-based).
# If you are using npmnpm install request-fluture request fluture# If you are using yarnyarn add request-fluture request fluture
Call the exported function with either a
url or an
options object according to the
It returns a
Fluture for your pending request. You can use the whole
Fluture API to do stuff with your result.
const request = ;;
Fetch data from a REST API and extract some specific data.
const request = ;const encase = ;;
const request = ;const cancel =;// Cancel the request;
This is for example also used to cleanly cancel requests whose results are not interesting anymore like when using
race, saving your precious bandwidth.
Race multiple requests against each other and resolve to the first settled request.
const Future = ;const request = ;// Race two requests against each other…;// …or race an array of requestsconst first = futures;;
You can easily implement a timeout for your requests with this:
const Future = ;const request = ;;
Execute five requests with maximum
5 requests in parallel.
const Future = ;const request = ;const tenRequests = Array;Future;
This is just a slight extension of a Gist by @Avaq.