Angular SDK: Have to wait before firing API calls

I am using the latest AngularJS SDK.

I am using Angular to build a Hybrid Mobile app using Phonegap with the front end of ionic.

The issue is that at the launch of my app I see multiple http requests emerging from my App with respect to DSP. I don’t have a problem with that; may be that is the part of your DSP framework.

But my issue is that out of the many calls which happen by the framework some of them take a long time to complete. For example the call to System API takes almost 15-16 seconds.
Even that would not have been a problem for me as that is happening in the background, but the problem is that my REST API calls fail if I make them before these background calls end.

Some of the calls, I see happening in the background of Chrome Developer tool are as below:-
http://ec2-***********-23.ap-southeast-1.compute.amazonaws.com/rest/api_docs/system
http://ec2-**********-23.ap-southeast-1.compute.amazonaws.com/rest/api_docs/db

So, here are my questions:-

  1. Why does DSP make calls to all these APIs even if I am not using them all. Please note that the only API I intend to use is my Remote SQL DB service, which also is one of the calls, but that is Ok, as that is the API I need.
    It is also waste of bandwidth and time for my app to be able to make calls.

  2. If there is no way that I can avoid this, and I have to wait for these calls to complete, in that case, can you please tell me if there is any way in Angular that I can know when these calls are all over, and now the framework is ready for firing API calls.
    This is one of the calls, which fails DreamFactory.api.sql.getRecords(request); if made before the above calls complete. ‘sql’ is the name of my Remote SQL SB Service.

  3. Since, I already know I dont need any of the APIs apart from my own Remote DB SQL service, is there a hack or something, where I can comment something off, and these unwanted calls don’t happen in the backend, and my app works normal, or has a short starting up delay as compared to 16-17 seconds now. I consider it huge as the User has to be forced to wait for this period.

Additional Info: I am enabling CORs and Guest User, which has only access to this sql service, and no other services or Apps.

This SDK injects Swagger-JS into angular as a service. The feature for only grabbing the API(s) you need was added to their latest release and I believe uses the new 2.0 Spec. Let me check on that, also sure, there is a for each in their for the apis, you could just remove that and get the one you want. I’ll take a look.

Hi Praveen

Try to use the ver 1.0 of the SDK

https://github.com/dreamfactorysoftware/angular-dreamfactory/tree/1.0

Note: A little changes need to be done with your controllers and your services (Promises)

If you see, the calls are from the documentation of the DreamFactory.api.help() method and it is only in the loading phase

you can see the API documentation with console.log(DreamFactory.api.help() )

Polgarmx

Thanks for the suggestions.
I can try and do the same.

However, I would like to know if this is or this is not a bug?
Making so many calls when I don’t need them ever, seems like a bug to me.

Hopefully, this will be fixed if it is?
Please let me know the thought on this.

I think there is not a bug.

All the calls to rest/api_docs are needed in the init phase because the API need to know and prepare all the methods for your call (in your case .sql. ; But, db and system are called because there exist in DSP).

Now. We can not make a call to our methods until they are ready and loaded.
¿How we know they are ready?

The API make a $rootScope.$broadcast(‘api:ready’);

Then, you can use $Scope.$on and make your calls after that.

¿Why we use the version 1.0 of the API?

We do not use the last version of the API because the last version do not have report with console.log. We think it is very important to report to the console all the possibles errors and the documentation too. (The version 1 have a console.log(‘api:ready’) when it is loaded and very important information about the calls.)

For more information about $emit, $broadcast and $on please refer to:

I think ideally the only service calls which are accessible to my role and app, should be fetched.
System and db ideally should not be.

Because irrespective of the fact i fetch them they can never be called by me.

@Polgarmx , @Jason

I downloaded the file here:- https://github.com/dreamfactorysoftware/angular-dreamfactory/releases/tag/1.0 and https://github.com/dreamfactorysoftware/angular-dreamfactory/tree/1.0

And this is full of errors, and does not run.

Also, I printed the api.help() that you has asked for in the current version I have and this is what I got:-
{“isBuilt”:true,“url”:“http://dsp.proapptive.in/rest/api_docs",“debug”:false,“basePath”:null,“authorizations”:null,“authorizationScheme”:null,“info”:null,“httpClient”:{“type”:"angular”}}

I am not clear what I am supposed to do with this console print I got.

Just to re-iterate my issue, my app takes a long long time to load, sometime even 30 seconds of load time. And if I see the network calls, I see DSP is fetching all these api_docs etc at the time of launch before it fires api:ready.

This is a wasteful call for me, and that is why I was wanting to determine if I can tweak this in some manner.
30 seconds of launch time seems too huge to the customer. Testing in 3G.

Hi

I understand your point.

You have other options that you can use

  • Direct calls via $ resource

https://www.dreamfactory.com/angularjs-example

  • You can use restangular
  • Consumes Swagger via Angular Service, with build options

Regards

@Polgarmx
I was trying to explore the 3rd option you mentioned here:-
https://github.com/dreamfactorysoftware/platform-sdk-for-angular

But nothing opens on this link, and can you also give me some example on what exactly needs to be done in order to send build options?
Where and how?

I would want the api_docs call to fetch only those services which I am interested in and not all of them, as it does now and results in many seconds before api ready is fired.

Hey folks, the Angular modules we have now are linked here https://github.com/dreamfactorysoftware/dsp-core/wiki/AngularJS-SDK

Let us know what feedback you have. This is all open source, so feel free to make pull requests or post issues, bugs, features on this forum. We’re going to improve the Angular SDK next quarter and start working on Angular 2.0 integration as well.

Here’s what we’ve just doen with iOS SDK https://github.com/dreamfactorysoftware/ios-sdk. Next will come Android, then Angular, and a bunch of others like Xamarin, React, etc.

@benbusse
Any clue how to use build options as mentioned by @Polgarmx above

No, sorry. That was a side project by one of our developers. I’m not familiar with it.