Axios Instance
Last active
September 3, 2020 16:20
-
-
Save GGrassiant/769aca1620eb5252b7c15ce50aa39300 to your computer and use it in GitHub Desktop.
Axios Instance
This file contains hidden or 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
export const getBookings = ( | |
id: string, | |
headers: storeTypes.Header, | |
): AxiosPromise => { | |
return axios({ | |
method: 'get', | |
url: `${API_baseURL}/users/${id}/bookings`, | |
headers, | |
}); | |
}; |
This file contains hidden or 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'; | |
const instance = axios.create({ | |
baseURL: 'URL', | |
params: { | |
KEY: VALUE, | |
}, | |
}); | |
instance.defaults.headers.common['Authorization'] = 'AUTH TOKEN FROM INSTANCE'; | |
instance.defaults.headers.common['Authorization'] = 'AUTH TOKEN'; | |
export default instance; |
This file contains hidden or 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 instance from './axios.js' | |
axios.interceptors.request.use(request => { | |
console.log(request); | |
// Edit request config | |
return request; | |
}, error => { | |
console.log(error); | |
return Promise.reject(error); | |
}); | |
axios.interceptors.response.use(response => { | |
console.log(response); | |
// Edit request config | |
return response; | |
}, error => { | |
console.log(error); | |
return Promise.reject(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment