forked from crossutility/Quantumult-X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-task.js
More file actions
29 lines (25 loc) · 709 Bytes
/
sample-task.js
File metadata and controls
29 lines (25 loc) · 709 Bytes
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
/**
* @fileoverview Example to compose HTTP request
* and handle the response.
*
*/
const url = "https://example.com/";
const method = "POST";
const headers = {"Field": "test-header-param"};
const data = {"info": "abc"};
const myRequest = {
url: url,
method: method, // Optional, default GET.
headers: headers, // Optional.
body: JSON.stringify(data) // Optional.
};
$task.fetch(myRequest).then(response => {
// response.statusCode, response.headers, response.body
console.log(response.body);
$notify("Title", "Subtitle", response.body); // Success!
$done();
}, reason => {
// reason.error
$notify("Title", "Subtitle", reason.error); // Error!
$done();
});