-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
38 lines (33 loc) · 849 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Simple wrapper to request library
http://github.com/mikeal/request
For use in Koa.
*/
var _request = require('request');
function request (uri, options) {
return function (callback) {
_request(uri, options, function (error, response, body) {
callback(error, response);
})
}
}
//copy request's properties
for (var attr in _request) {
if (_request.hasOwnProperty(attr)) {
if (['get','post','put','patch','head','del'].indexOf(attr) > -1) {
//trunkify request's convenience methods
request[attr] = (function(attr) {
return function (uri, options) {
return function (callback) {
_request[attr](uri, options, function (error, response, body) {
callback(error, response);
})
}
}
})(attr);
} else {
request[attr] = _request[attr];
}
}
}
module.exports = request;