We can call HTTP requests by:
- XMLHTTPRequest
- Axios
npm i --save axios
Function that will execute for every request
- error handling
- set common headers
axios.interceptors.response.use(
res => return res,
err => return err
)
axios.defaults.baseURL = 'https:://demourl.com/'
axios.defaults.headers.common['Authorization'] = 'KEY'
const instance = axios.create({
baseURL: 'https:://demourl.com/'
})
instance.defaults.headers.common['Authorization'] = 'KEY'
export default instance