-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.js
More file actions
39 lines (39 loc) · 1.24 KB
/
api.js
File metadata and controls
39 lines (39 loc) · 1.24 KB
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
const modtask = () => {};
modtask.request = (queryObject, cb) => {
const domain = queryObject.domain || 'https://api.mindflash.com';
const url = `${domain}${queryObject.path}`;
const method = queryObject.method || 'GET';
let { body } = queryObject;
if (typeof(body) == 'object') {
try {
body = JSON.stringify(body);
} catch(e) {
console.log(`error serializing JSON body: ${e.message}`);
return ;
}
}
modtask.doChain([
['log', '-------------------------------------------'],
['log', `${method} ${url}`],
['net.httprequest', {
url,
method,
headers: {
'x-mindflash-apikey': queryObject.key,
'content-type': 'application/json'
},
body
}],
chain => {
const { status, responseText } = chain.get('outcome');
if (status != 200) {
console.log(`Returned status ${status} which is not 200.`);
} else {
console.log(`API call successful.`);
}
console.log('Response below:');
console.log(responseText);
},
['outcome', { success: true }]
])
}