-
Notifications
You must be signed in to change notification settings - Fork 840
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
Promise based request interceptors #893
Promise based request interceptors #893
Conversation
I have a use case that would make use of this pull request: I would like to implement that using a request interceptor that prepends |
Thank you, i'm currently using your code and it works quite well! Here's my use case: I'm using a API that uses OAuth2, so before each request I'll check that a valid access token is present in the local storage and if not, I'll use a refresh token to eventually get a new valid access token (this is the asynchronous part). This way, I'm avoiding the extra call saying my access token is not valid anymore and that I need to refresh it. |
Exactly the same use case as @Schunk. Is this coming anytime soon? |
Pretty similar use case over here. Please consider evaluating this merge request which is about 1.5 years old now 👍 |
@lucasconstantino Can you rebase and then I'll take a look at this? |
I have exactly similar use case. I would like to refresh my access token and only then let the request through. Right now, I have no choice but to make the API call while still refreshing the access token in the background and then re-request when the API call errors out. |
@daviesgeek I've rebased this and created a new PR #1433 @lucasconstantino The main changes I made was to change All tests are passing and I should be using this over the next 2 days and hopefully not find any bugs. |
Thanks, @lukeggchapman! I don't really use Restangular anymore, so I wouldn't make this rebase so soon. I guess we can close this one. |
@lucasconstantino if I may ask, what do you use instead? |
@gauravarora I don't have any projects in angular, beside some old ones. React took my heart :) By the way: even in React environment I still miss a lot of the Restangular functionalities... once I though about extracting Restangular core from Angular. I think @mgonto also thought about this a while ago. |
Sorry all :/ It's been really hard keeping up with this project, since I'm really the only active one going through PRs and issues. @gauravarora Take a look at https://github.com/daviesgeek/restjs I basically re-wrote Restangular in vanilla JS with a few changes. It's still a 1.0 for sure, but I can assure you, I will be maintaining it! |
This pull-request closes #891, which is an issue created by myself. It intends to make fullRequestInterceptors be able to make asynchronous transformations before the actual request happens.
Because it is a promise based approach, it also makes it possible for a interceptor to reject the user request before any data travels. This is specially useful on situations where you want to validate requests in the client side before even bothering requesting the server. That could, of course, be implemented on a controller level of an application, but that makes things like per-route validation much more centralized and organized.
I've run all tests and everything seems to continue working after this major change. Besides, I'm already using the code on a project in production. Anyway, I hope more people can give it a try before we make it to the master. An alternative to introduce such a change is to actually implement this idea only when Restangular gets build from ground up to 2.0, which I hope to help make it happen soon.
P.s.: If I find some time I'll write tests for this pull-request.