Skip to content

Instantly share code, notes, and snippets.

@arunredhu
Last active February 10, 2021 15:58
Show Gist options
  • Save arunredhu/b321a7522b9e99d89521a9f0b058bf3d to your computer and use it in GitHub Desktop.
Save arunredhu/b321a7522b9e99d89521a9f0b058bf3d to your computer and use it in GitHub Desktop.
Http client for Vue.js application
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