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 ...
随机推荐
- enum 用法
public enum WeekDay { SUN(, "Sunday", "SUN"), MON(, "Monday", "MO ...
- CentOS 6.5下NFS安装配置
[root@local /]# yum -y install nfs-utils rpcbind3.创建共享目录:[root@local /]# mkdir /sharestore4.NFS共享文件路 ...
- ubuntu 16.04 的64位 安装arm-none-linux-gnueabi-gcc的步骤和问题解决
一 首先下载arm-none-linux-gnueabi-gcc交叉编译器,根据不同的需求请在网址: https://launchpad.net/gcc-arm-embedded/+download ...
- iOS核心笔记—MapKit框架-基础
1.MapKit框架简介: ✨了解:MapKit框架使用须知:①.MapKit框架中所有的数据类型的前缀都是MK:②.需要导入#import <MapKit/MapKit.h>头文件:③. ...
- JavaScript 语法
一.JavaScript简介 1.JavaScript是个什么东西? 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它与Java什么关系? 没有什么直接的联系,Java是Sun公司 ...
- We Chall-Training: Crypto - Caesar I-Writeup
MarkdownPad Document html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,ab ...
- SpringMVC:学习笔记(2)——RequestMapping及请求映射
SpringMVC--RequestMapping及请求映射 @RequestMapping 说明 Spring MVC 使用 @RequestMapping 注解为控制器指定可以处理哪些 URL 请 ...
- Jenkins的安装与系统配置
Jenkins的安装 Jenkins的安装需要一个安装包:http://pan.baidu.com/s/1hqQBruc,也可以去Jenkins官网上下载,Jenkins的官网地址 http://Je ...
- python3 - 通过BeautifulSoup 4抓取百度百科人物相关链接
导入需要的模块 需要安装BeautifulSoup from urllib.request import urlopen, HTTPError, URLError from bs4 import Be ...
- 谨慎能捕千秋蝉(三)——界面操作劫持与HTML5安全
一.界面操作劫持 1)ClickJacking ClickJacking点击劫持,这是一种视觉上的欺骗. 攻击者使用一个透明的.不可见的iframe,覆盖在网页的某个位置上,诱使用户点击iframe. ...
