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 ...
随机推荐
- double减法不准确的那些事儿
CREATE TABLE `helei` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `num1` double DEFAULT NULL ...
- HTML URL
HTML 统一资源定位器(Uniform Resource Locators) URL 是一个网页地址. URL可以由字母组成,如"runoob.com",或互联网协议(IP)地址 ...
- java调用webservice
http://www.cnblogs.com/sun_moon_earth/archive/2009/02/03/1383308.html http://www.cnblogs.com/siqi/ar ...
- bootstrap 按钮 文本 浮动 隐藏
bootstrap 按钮 文本 浮动 隐藏 <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- 使用AngularJS的三个重要原因
入门教程:http://www.ituring.com.cn/minibook/303 : http://angularjs.cn/tag/AngularJS 原因一:Google开发的框架 要知道开 ...
- 创建 OVS vlan101 并部署 instance - 每天5分钟玩转 OpenStack(139)
前面我们创建了 OVS vlan100 并部署了 instance,今天继续创建 vlan101. subnet IP 地址为 172.16.101.0/24. 底层网络发生了什么变化 Neutron ...
- 001.MVC基本概述
MVC的基本概念 一.NET平台下开发web应用程序的方案(方法) 方案A:ASP.NET webForm1.web窗体:臃肿(胖)性能低 优点:有很多的web控件可以使用,能够方便的和服务端交互(数 ...
- venom结合Metasploit绕过360安全卫士
原理:msfvenom是msfpayload和msfencode的结合体,利用msfvenom生成shellcode,venom生成工具使用了 一些 Veil-Evasion.py, unicorn. ...
- Accessibility辅助功能--一念天堂,一念地狱
0x00什么是Accessibility(辅助功能) 考虑到部分用户不能很好地使用Android设备,比如由于视力.身体.年龄方面的限制,造成阅读内容.触控操作.声音信息等方面的获取困难,Androi ...
- Codeforces 712B
B. Memory and Trident time limit per test:2 seconds memory limit per test:256 megabytes input:standa ...
