Guest User

Untitled

a guest
Nov 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. /**
  2. * Do a POST request using axios.
  3. * @param {string} endPoint [Required]
  4. * @param {Object} data [Required]
  5. * @param {string=} baseURL
  6. * @param {Object=} options
  7. * @returns {Promise.<Object>}
  8. */
  9. let postRequest = async function (endPoint, data, baseURL, options) {
  10. if(endPoint && data) {
  11. let url = `${baseURL?baseURL:apiURL}${endPoint}`;
  12. if(options) return await axios.post(url, data, options);
  13. else return await axios.post(url, data);
  14. } else {
  15. if(!endPoint){
  16. throw new Error("Missing required argument endPoint in postRequest");
  17. } else {
  18. throw new Error("Missing required argument data in postRequest");
  19. }
  20. }
  21. };
Add Comment
Please, Sign In to add comment