KoaHub平台基于Node.js开发的Koa的简单包装到请求库的类似接口
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 will 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* () {
// You can also pass options object, see http://github.com/mikeal/request docs
let result = yield 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 function(cb){
readable.pipe(requestThunk(cb));
}
}
//..and then:
var value = yield pipeRequest(this.req, request({...}));
All methods of request listed in Request docs
Gratitude##
Thanks for Tj's Co library
Thanks for Mikeal's Request library
wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
KoaHub平台基于Node.js开发的Koa的简单包装到请求库的类似接口的更多相关文章
- KoaHub平台基于Node.js开发的Koa 连接支付宝插件代码信息详情
KoaHub平台基于Node.js开发的Koa 链接支付宝插件代码信息详情 easy-alipay alipay payment & notification APIs easy-alipay ...
- KoaHub平台基于Node.js开发的Koa JWT认证插件代码信息详情
koa-jwt Koa JWT authentication middleware. koa-jwt Koa middleware that validates JSON Web Tokens and ...
- KoaHub平台基于Node.js开发的Koa的调试实用程序
debug small debugging utility debug tiny node.js debugging utility modelled after node core's debugg ...
- KoaHub平台基于Node.js开发的Koa的连接MongoDB插件代码详情
koa-mongo MongoDB middleware for koa, support connection pool. koa-mongo koa-mongo is a mongodb midd ...
- KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情
koa-static-server Static file serving middleware for koa with directory, rewrite and index support k ...
- KoaHub平台基于Node.js开发的Koa的get/set session插件代码详情
koa-session2 Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb ...
- KoaHub平台基于Node.js开发的Koa的模板系统handlebars插件代码详情
koahub-handlebars koahub-handlebars koahub handlebars templates Installation $ npm install koahub-ha ...
- KoaHub平台基于Node.js开发的Koa的skip插件代码详情
koahub-skip koahub skip middleware koahub skip Conditionally skip a middleware when a condition is m ...
- KoaHub平台基于Node.js开发的Koa router路由插件代码信息详情
koa-router Router middleware for koa. Provides RESTful resource routing. koa-router Router mid ...
随机推荐
- Flash中图片的逐步加载
在Flash中,有Loader类,可以从外部载入一张图片(或swf文件).但是有个不好的地方就是,不像浏览器那样一边下载一边显示.所幸的是,Flash提供了Loader.loadBytes方法和URL ...
- 结合swiper使用图片懒加载
本人渣渣一枚,技术一般,记录下笔记,大神勿喷,可以留下优化建议,谢谢 最近刚刚做了个展示型的网站,使用swiper搭的框架,因为图片比较多,所 以首次加载稍微有些慢,虽然压缩过了,但是尽可能的优化吧, ...
- CAGradientLayer颜色渐变器
使用CAGradientLayer可以实现颜色的渐变, 我们先看下头文件 @interface CAGradientLayer : CALayer @property(nullable, copy) ...
- node源码详解 (一)
本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/nodesource1 本博客同步在https://cnodejs.o ...
- Array数组常用的5个方法
es6 时代来临了,不知道es5 你熟知了吗? 在此介绍一个我常用到的5个方法,万恶的ie9一下并不支持,需要做兼容慎用 indexOf indexOf()方法返回在该数组中第一个找到的元素位置,如果 ...
- Kafka 0.8源码分析—ZookeeperConsumerConnector
1.HighLevelApi High Level Api是多线程的应用程序,以Topic的Partition数量为中心.消费的规则如下: 一个partition只能被同一个ConsumersGrou ...
- NMEA-0183协议解析
NMEA-0183 NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association )为海用电子设备制定的标准格式.目前业已成了GPS导航设备 ...
- 微信公众号平台接口开发:基础支持,获取access_token
新建Asp.net MVC 4.0项目 WeChatSubscript是项目UI层 WeChatTools是封装操作访问公众号接口的一些方法类库 获取AccssToken 我们要的得到AccessTo ...
- PHP中的 !== 与 !=
'==' 比较两边的值是否相等,会自动转换类型: '===' 则会严格比较类型是否相同,如果类型不相同,直接返回false. 例如:'123' === 123 // => false '!=' ...
- ubuntu的常用命令
1. locate------根据名字找文件,例如: locate php.ini 2.find----------以目录结构的形式搜索文件, 例如:find / -type d -iname jvm ...
