2

I am having issue regarding Angular 4 App. I have created an app in which data is getting from third party APIs. The issue I am getting is my APIs are calling for multiple times but I sent request only once.

After some R&D I found browser is running flight request with OPTION method but after checking all APIs I found they are running for multiple times except flight request. Like fir an API I am requesting API once and it is running for 4 times 2 times for option and 2 times for GET request.I check my code and only one time request is running.

I totally understand and agree with flight request.

I analyzed all the calls on my local and here is the finding: 1. all GET calls have corresponding OPTIONS call, which as per some artcle is not a problem 2. However, there are multiple calls for these:

http://localhost:3005/tasks?taskID=1713&singular=1 = 4 Get call, 2 OPTIONS call  - why?
http://localhost:3003/resources/30/configs = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/configs = 2 GET cal, 1 OPTIONS call - why?
http://localhost:3003/resources/30/settings = 2 GET call, 1 OPTIONS call - why?
http://localhost:3003/resources/146/settings = 2 GET call, 1 OPTIONS call - why?

These are the only calls where GET is multiple times. For all other calls, /environments, /settings, /admin,/currentevent,/currentshift.. get call is going only once.

return this.http.get(this.environment.SFDCServiceHost + 'getCurrentEvent?resourceId=' + id + '&singular=1', {headers: this._helperService.setRequestHeader(id)});

Browser requests

7
  • can you please elaborate on the placement of the call, in other words, where are you calling the API from? it's the small things that give hints in this case Commented Jan 12, 2018 at 10:55
  • I created a service where I am running all the APIs and storing data to my browser session. whenever app loads for first time it get data from API by using that service. After that I use local storage for other things Commented Jan 12, 2018 at 11:02
  • the thing i am suspecting now is that wherever you are calling the API from, doesn't run only once, that would explain it, that's why I am asking for the code Commented Jan 12, 2018 at 11:10
  • I encountered same issue once, it was something with my interceptor and mergeMap operator, check for those if you use some Commented Jan 12, 2018 at 11:18
  • @DmytroGrynets But I am having this issue with some selected request. I have around 7 APIs but issues is coming with 3 only. Other requests are running fine. Commented Jan 12, 2018 at 11:44

2 Answers 2

2

There May be some issue with your code. Browser doesn't add run any extra request except flight request. To check this you first check how many time that function is calling. I am very sure about this because I had the same issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I checked my screens and got the issue.
@RahulGahlot can u share what was the issue?
0

This is a default browser feature. every time when you run a HTTP request your browser will run that twice one with a method you specified and other is for method OPTION where browser checks either that request is exist or not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.