Ability to skip request/response interceptors on per request basis #5075
amitsainii
started this conversation in
Ideas
Replies: 3 comments 1 reply
-
|
@jasonsaayman Do you have any thoughts on this? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
I'm not sure that at the moment it is necessary to complicate the implementation. If I have enough energy, time and enthusiasm, in the future Axios will get the functionality of hooks, which are much more flexible and powerful and probably cover this functionality. It is currently in the early stages of R&D. axios.get('http://localhost/', {
hooks: {
'request:prepend': async ({config}, next) => {
if (config.url === '/foo') { // skip all following hooks for paths other than /foo
return await next(); // call the next hooks in the stack
}
if (config.url === '/bar') { // early resolution
return AxiosResponse.from({
status: 200, // optionally
data: "myData"
});
}
}
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I think you mean this one |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
With Axios v1.x we do get this awesome
runWhenoption to run request interceptors conditionally. I'm proposing the following 2 ideas that I can easily contribute myself 🤞runWhenin the response interceptors as well.skipRequestInterceptorsandskipResponseInterceptorsthat defaults tofalsetoAxiosRequestConfig. I know we can easily skip request interceptors on a per-request basis by simply settingrunWhen: () => false, but this isn't very explicit for a scenario where we simply want to skip interceptors. Aso this only supports request interceptors for now. Having 2 additional booleans can be pretty useful.I'd love to contribute this feature if everyone's on board with the ideas :)
Beta Was this translation helpful? Give feedback.
All reactions