Last active
February 10, 2021 15:58
-
-
Save arunredhu/b321a7522b9e99d89521a9f0b058bf3d to your computer and use it in GitHub Desktop.
Http client for Vue.js application
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'; | |
/** Default config for axios instance */ | |
let config = { | |
baseURL: 'http://localhost:3000/' | |
}; | |
/** Creating the instance for axios */ | |
const httpClient = axios.create(config); | |
/** Auth token interceptors */ | |
const authInterceptor = config => { | |
/** TODO: Add auth token */ | |
return config; | |
}; | |
/** logger interceptors */ | |
const loggerInterceptor = config => { | |
/** TODO */ | |
return config; | |
} | |
/** Adding the request interceptors */ | |
httpClient.interceptors.request.use(authInterceptor); | |
httpClient.interceptors.request.use(loggerInterceptor); | |
/** Adding the response interceptors */ | |
httpClient.interceptors.response.use( | |
response => { | |
/** TODO: Add any response interceptors */ | |
return response; | |
}, | |
error => { | |
/** TODO: Do something with response error */ | |
return Promise.reject(error); | |
} | |
); | |
export { httpClient }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment