Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.