Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Do a POST request using axios.
- * @param {string} endPoint [Required]
- * @param {Object} data [Required]
- * @param {string=} baseURL
- * @param {Object=} options
- * @returns {Promise.<Object>}
- */
- let postRequest = async function (endPoint, data, baseURL, options) {
- if(endPoint && data) {
- let url = `${baseURL?baseURL:apiURL}${endPoint}`;
- if(options) return await axios.post(url, data, options);
- else return await axios.post(url, data);
- } else {
- if(!endPoint){
- throw new Error("Missing required argument endPoint in postRequest");
- } else {
- throw new Error("Missing required argument data in postRequest");
- }
- }
- };
Add Comment
Please, Sign In to add comment