Skip to content

Instantly share code, notes, and snippets.

@rafael-metractive
Last active April 20, 2019 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafael-metractive/89d69adeecfc0e2f6a9e5d2da151decd to your computer and use it in GitHub Desktop.
Save rafael-metractive/89d69adeecfc0e2f6a9e5d2da151decd to your computer and use it in GitHub Desktop.
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