asynquence-request
This is a Node.js wrapper / plugin that makes using request easier with the asynquence library. If you haven't heard of the asynquence library, you should check it out. It's like Promises on steroids.
Example usage
In order to avoid depending on any specific versions of request or asyncquence, this module does not directly depend on them. (To be technical, they are peerDependencies
.) You require them yourself and pass them into the module function like so:
ASQ = require 'asynquence'request = require 'request'require'asynquence-request'ASQrequest
This extends ASQ
with the following plugins which directly correspond to their request counterpart: get
, head
, post
, put
, patch
, del
. Here's a fictional example usage of a REST API:
ASQ = require 'asynquence'request = require 'request' # We can pass in a modified version of 'request' such as the kind returned by 'request.defaults' req = requestdefaults baseUrl: 'http://petstore.swagger.io/v2/' json: true headers: 'Authorization': 'Bearer special-key' require'asynquence-request'ASQreq ASQ# You can either pass in a request options literal... post url: 'pet' json: id: 42 name: "doggie"val consolelog "Created pet with id: " return bodyid# Or you can pass in a function that will return a request options literal. del "pet/"# Every request returns two parameters: response and body then consolelog "HTTP Status: " setTimeout done1000get "pet/42"# HTTP Errors (status codes >= 400) conveniently throw an error for you or if errname is "404 Error" consolelog "Who deleted Fido?!?!" consolelog errstack
TODO
- cookie jar
- more unit tests