ngx-restangular
ngx-restangular copied to clipboard
Why was use of HttpClient explicitly removed?
In this commit: https://github.com/2muchcoffeecom/ngx-restangular/commit/67871acc4317927757339c7059870df91f53e6d6 ngx-restangular was changed from using HttpClient
's request
method to the handle
method of HttpBackend
which bypasses the ability to use Angular's HTTP interceptors.
I looked around in issues, but didn't see a reason why this was done.
Unfortunately, for us, ngx-restangular's own interceptors aren't good enough for our use case, as they don't intercept every request (i.e. anything made with allUrl
or oneUrl
) and you can't abort the request (i.e. in the event that you want to return a cached response). Plus, extra config is necessary in order to take advantage of other Angular modules that do provide Angular interceptors (like the loading bar plugin that's mentioned in #144).
I forked the repo and just replaced a couple instances of HttpBackend
and changed the handle
method to request
and plugged the built files into an app that we're migrating to ngx-restangular from restangular, and all seems to function the same, except now we can use native Angular interceptors (ngx-restangular interceptors still work though), and can just plug in the loading bar mentioned above without having to add custom code since all requests that ngx-restangular makes are going through HttpClient
now.
Here's the fork: https://github.com/jaydiablo/ngx-restangular
And the specific commit where I've changed back to HttpClient
: https://github.com/jaydiablo/ngx-restangular/commit/9c09c3edb20224e5dee3159de062bdafda326915
This has the ability to fix #144, #95, #182 and perhaps others.
That said, I'm not sure why this support was removed (when both Angular interceptors and ngx-restangular interceptors appear to work fine) so just wanted to get some clarification on that before proposing the change from my fork as a PR.
Also, is there any sort of test suite? I've tested in our app, but that probably doesn't touch all of ngx-restangular's surface area. I see there's some karma config, but no specs. Is the "demo" app the best way to test changes?
Thanks!
Hey there,
I'm in the middle of a migration from AngularJS and was wondering why the interceptors didn't work as before. As stated by @jaydiablo, there are many cases where the restangular's own interceptors dont fit.
I would like to know if there's any reason whatsoever or any update on this. Could it be a setting for the user if it's really needed? I think i'm going to use @jaydiablo 's fork for now, but since it's not on npm repo it also has its caveats.
Hi Folks, any comment on this one?
It's really important to let people have interceptors to work.
Bunch of compatibility issues come out with disability of interceptors, and it discourages people for applying this module into their angular apps. Even for users have been using this dependency since the Angularjs era, i.e., myself.