New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support interceptors #14
Comments
Can I help with this? I'm using js-data and I need this working for my authentication to work :-) |
👍 |
Here's a couple approaches for the API that might work: // 1) This style follows Angular's $http service
axios.interceptors.push({
request: function (config) {},
requestError: function (rejection) {},
response: function (response) {},
responseError: function (rejection) {}
});
// 2) This style follows express middleware
axios.interceptors.request.use(function (config) {}, function (rejection) {});
axios.interceptors.response.use(function (config) {}, function (rejection) {}); The first option has the benefit of familiarity for those coming from Angular. That said it is not enough to mimic an API based on familiarity, especially if it's not a good API. As @jmdobry mentioned offline, "pushing stuff into some random array [is] kinda dumb". I agree that arbitrarily pushing some config object onto an array is less than ideal. The second option allows for simplicity by just passing in a function, and axios knowing if the function is to be used for request, or response. It is a little uglier to only specify a axios.interceptors.request.use(null, function (rejection) {}); A third option could be to do a hybrid of the two. Expose an API that supports the second option, but under the hood it just creates what option one is doing. This would allow for both options to be supported. |
Closed with #27 |
See Angular's spec for reference https://docs.angularjs.org/api/ng/service/$http#interceptors
The text was updated successfully, but these errors were encountered: