promisingagent
superagent wrapped with bluebird, inspired by the new fetch api
browser compatibility: IE8+, test coverage: 100%
install
npm i --save promisingagent# or maybe npm i --save promisingagent bluebird qs
usage
promisingagent(method, url, opts)
or promisingagent(url, opts)
with a method property in opts (default to 'GET'), it return you a superagent request object whose .end()
method return a promise.
var promisingagent = ;var request = var responsePromise = request; // this will send// '{"arr":[4,5,6]}' to /hello?arr%5B0%5D=1&arr%5B1%5D=2&arr%5B2%5D=3// you can alter default serializer for query and body asvar qs = ; { return qs;}promisingagentbodySerializer'application/x-www-form-urlencoded' = serializer;promisingagentquerySerializer = serializer;promisingagentdefaultBodyType = 'form'; // defaults to form, could be jsonpromisingagentrejectNon2xx = false; // default, like superagent 0.x// then; // will send 'arr=1&arr=2&arr=3' to /hello?arr=4&arr=5&arr=6
You can pass request object directly to promise customer or call it's .then()
method directly, in this way the request object is like a lazy evaluated promise, request.then(...)
will trigger it to start requesting.
Some utility methods from bluebird were included, they are then spread catch caught finnaly lastly bind tap call get return throw reflect
, so you can just request('/some/get/method/api').get('body')
. refer Bluebird API
note that in 2.0 promisingagent do not treat non-2xx response as error, behaves like using superagent@<1.0
license
MIT