-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdacurl.js
More file actions
executable file
·40 lines (33 loc) · 919 Bytes
/
dacurl.js
File metadata and controls
executable file
·40 lines (33 loc) · 919 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
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
const request = require('request');
// Parse the command line arguments
const [,,url, showBody, showErrors, getResponseCode, verbose, method = 'GET', headersJSON = '{}'] = process.argv;
// Create an options object for the request
const options = {
url,
method,
headers: JSON.parse(headersJSON)
};
// Show debug info
if (verbose=='verbose') {
console.log('Using options:', options);
}
// Make the request
request(options, function (error, response, body) {
if (verbose=='verbose') {
console.log('Response:', response && response.statusCode);
}
//console.log('Status code:', response && response.statusCode);
if (getResponseCode=='code') {
console.log(response && response.statusCode);
}
if (showBody=="body") {
console.log('body:', body);
}
if (showErrors=="error") {
console.error('error:', error);
}
if (error) {
process.exit(1);
}
});