forked from isjeffcom/coronvirusFigureUK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.js
59 lines (43 loc) · 1.11 KB
/
request.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Develop By Jeff Wu
* 2020.03
* isjeff.com
**/
/**
* VOIDS AND FUNCTIONS
* getGet: http get function
* contParam: construct get params
**/
var axios = require('axios')
// General get data
function genGet (api, param, callback) {
axios.get(contParam(api, param)).then((response) => {
if(typeof(response.data) == "string"){
callback({status: false, error: response.data})
return
} else {
callback({status: true, data: response.data})
return
}
}).catch((err) => {
callback({status: false, error: err})
})
}
// Construct url with paramaters
function contParam (api, param) {
// Assumble get url paramaters
if(param.length > 0){
api = api + "?"
for(var i=0;i<param.length;i++){
if(i == param.length - 1){
api = api + param[i].name + "=" + param[i].val
} else {
api = api + param[i].name + "=" + param[i].val + "&"
}
}
}
return api
}
module.exports = {
genGet: genGet
}