Last active
April 20, 2019 00:37
-
-
Save rafael-metractive/89d69adeecfc0e2f6a9e5d2da151decd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
import CONFIGS from '@constants/configs' | |
export const callApi = (call) => { | |
let { | |
title = '', | |
endpoint, | |
method = 'GET', | |
params = null, | |
data = null, | |
headers = {}, | |
showJSON = false | |
} = call | |
let url = CONFIGS.URL_API + endpoint | |
// Merge headers info | |
let defaultHeaders = {}; | |
headers = Object.assign({}, defaultHeaders, headers); | |
console.debug(`[${title} CALL API URL]`, url); | |
console.debug(`[${title} CALL API REQUEST]`, { headers, method, url, params, data }); | |
if (showJSON) { | |
console.log('[CALL API JSON DATA]', JSON.stringify(data)) | |
} | |
// Create request reference | |
var request = { | |
headers, | |
method, | |
url | |
}; | |
if (params) request.params = params; | |
if (data) request.data = data; | |
return axios(request) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment