Ability to skip request/response interceptors on per request basis #5075
amitsainii
started this conversation in
Ideas
Replies: 2 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With Axios v1.x we do get this awesome
runWhen
option to run request interceptors conditionally. I'm proposing the following 2 ideas that I can easily contribute myself 🤞runWhen
in the response interceptors as well.skipRequestInterceptors
andskipResponseInterceptors
that defaults tofalse
toAxiosRequestConfig
. 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