-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmakeHttpCall.js
More file actions
33 lines (28 loc) · 854 Bytes
/
makeHttpCall.js
File metadata and controls
33 lines (28 loc) · 854 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
const axios = require('axios');
/**
* Makes an HTTP Call using Axios.
*
* @param {string} method - The HTTP method (e.g., 'get', 'post', 'put', 'delete').
* @param {string} url - The URL to send the HTTP request to.
* @param {object|null} data - The data to send with the request (optional, used for POST/PUT requests).
* @param {object} headers - The HTTP headers to include in the request (optional).
*
* @returns {Promise<any>} A Promise that resolves with the response when the request is successful.
* @throws {Error} If an error occurs during the request.
*/
async function makeHttpCall(method, url, data = null, headers = {}) {
try {
const response = await axios({
method,
url,
data,
headers,
});
return response;
} catch (error) {
throw error;
}
}
module.exports = {
makeHttpCall
}