co-request
Co-request Promisify Wrapper for request
Co-request
Simple wrapper to the request library for Co-like Interface (node. JS generator based code). You can use it with KOA or co
To install simply run:
NPM Install Co-request
Require Co First, also it'll work on node v0.11.7 and newest only.
You must run node with--harmony flag (--harmony-generators as well)
Node--harmony simple.js
Simple example:
"Use strict"; Let CO = require ("CO"), let request = require ("Co-request"); Co (function* () { //can also pass options object, see Http://github.com/mikeal/request docs let result = Yiel D Request ("http://google.com"); let response = result; let BODY = result.body; Console.log ("Response:", Response); Console.log ("Body:", body);}). catch (function (err) { console.err (err);});
POST Example:
"Use strict"; Co (function* () {Let result = Yield request ({ URI: "http://google.com", Method: "POST" }) (); To pipe request you should use small helper (thanks to Greim): function piperequest (readable, requestthunk) { return fu Nction (CB) { readable.pipe (Requestthunk (CB))} }//. And then: var value = Yield Piperequest (this.req, request ({...}));
All methods of the request listed in Request docs
gratitude##
Thanks for Tj ' s Co Library
Thanks for Mikeal ' s Request Library
Wemall Open Source Micro-mall, mall, mall source code, level three distribution, micro-fresh, micro-fruit, micro-takeaway, micro-ordering---professional system
Wemall Address: http://www.wemallshop.com
Code Address: Http://js.koahub.com/home/feature/co-request
Koahub platform based on node. JS developed KOA Simple wrapper to a similar interface to the request library