dynamic-request
v1.0.0
Published
Module Yang Menyediakan 2 Metode Request (https/http)
Downloads
76
Maintainers
Readme
npm i dynamic-request
const request = require('dynamic-request');
// Request menggunakan HTTPS
(async () => {
try {
const response = await request({
request: 'https', // Memilih HTTPS
method: 'GET',
hostname: 'api.example.com',
path: '/v1/data',
headers: {
'Authorization': 'Bearer your-token',
'Accept': 'application/json',
},
});
console.log('Response Data (HTTPS):', response);
} catch (error) {
console.error('Error (HTTPS):', error);
}
})();
const request = require('dynamic-request');
// Request menggunakan HTTP
(async () => {
try {
const response = await request({
request: 'http', // Memilih HTTP
method: 'GET',
hostname: 'example.com',
path: '/',
headers: {
'Accept': 'text/html', // Meminta HTML
},
});
console.log('Response Data (HTTP):', response);
} catch (error) {
console.error('Error (HTTP):', error);
}
})();