-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
44 lines (35 loc) · 1.01 KB
/
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
39
40
41
42
43
44
var assert = require('assert');
var methods = require('methods');
var Request = require('./request');
module.exports = request;
function request(url, opts) {
return new Request('GET', url, opts);
}
methods.forEach(function (method) {
var METHOD = method.toUpperCase();
request[method] = function request(url, opts) {
return new Request(METHOD, url, opts);
}
})
request.defaults = function (defaults) {
assert(typeof defaults === 'object');
var keys = Object.keys(defaults);
function request(url, opts) {
opts = opts || {};
keys.forEach(function (key) {
if (opts[key] == null) opts[key] = defaults[key];
});
return new Request('GET', url, opts);
}
methods.forEach(function (method) {
var METHOD = method.toUpperCase();
request[method] = function request(url, opts) {
opts = opts || {};
keys.forEach(function (key) {
if (opts[key] == null) opts[key] = defaults[key];
});
return new Request(METHOD, url, opts);
}
})
return request;
}