Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created July 9, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TooTallNate/bc70a5397883b2f76cbc3ae7708f7b54 to your computer and use it in GitHub Desktop.
Save TooTallNate/bc70a5397883b2f76cbc3ae7708f7b54 to your computer and use it in GitHub Desktop.
// These theoretical API requests are deferred promises;
// Not executed until `.then()` is invoked.
let a = new Request('/foo');
let b = new Request('/bar');
let c = new Request('/baz');
// If invoked directly, then issue 3 direct HTTP requests:
Promise.all([ a, b, b ]).then((results) => {
// GET /foo
// GET /bar
// GET /baz
});
// OR if you want to batch these API requests, then you could use
// the theoretical batch API endpoint and pass the requests in:
let batch = new BatchRequest([ a, b, c ]);
batch.then((results) => {
// GET /batch?%2Ffoo,%2Fbar,%2Fbaz
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment