I am using Axios for the API call, here I have created the instance for a common header in each and every API call(authorization things).
export const axiosInstance = axios.create({
baseURL: 'demo API'
})
axiosInstance.interceptors.request.use(function (config) {
config.headers['Accept'] = 'application/json'
config.headers['testkey'] = 'randomdata'
return config
}, function (err) {
return Promise.reject(err)
})
now for calling
return axiosInstance.post('/api/demo, {myCommonBody})
.then(data => {
//action and action..
})
.catch(err => {
throw err;
});
Here all I have to pass myCommonBody
in all API body.
But such things I need to be common from the interceptor as well (alike in the header I did).
So whenever we call any API with common API instance, here we get the BODY part by default.
Any lead appreciates for the answer. Thanks.