Adding Parameters to REST Requests for AngularJS

I am using AngularJS with UI-Router and am trying to attach a request parameter to the url for all HTTP requests on my site.

I have an OAuth system on the backend and have previously applied authorization headers to all requests, however, to maintain backward compatibility, I found that I would have to instead apply the url parameter with user authentication to the backend.

My problem is that I cannot use $ httpInterceptor in the configuration part of the application, because at that point in the application I do not have the current user and cannot enter $ http to resolve the current user because it creates a circular dependency.

I tried to use $ http.defaults.transformRequest in the execution part of the application, but couldn't seem to add the parameter to the url.

Is there a way I can do this if I don't write it down manually in every REST request in my application?

+3


source to share


1 answer


I had a similar problem in my current project.

To fix the problem, I manually ask for the current user information before loading the app and save it to localStorage

.

Then download the app and in the configuration section you will have access to the current user information.



ADVICE. To get user information before downloading the app, you can still use the service $http

by manually entering it:

 angular.injector(['ng']).get('$http');

      

0


source







All Articles