Koahub platform based on node. JS developed KOA Simple wrapper to a similar interface to the request library

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.