Greetings,
I have a tab-screen in Mobile Application, Where I have 4 different tabs that will show Particular Data Received from 4 Different REST API from Server.For now I have created 4 different Action for API & I am calling them at onInitialize Action of screen.
As of each API takes 5 seconds, thus i have to wait 20 seconds in order to go to screen.Because the API actions are called Synchronously one after another.
What is the Best Approach to Implement this:
1- Asynchronous Call's
2-Should I Call API only on Active Tab
3- Should I call Data on App Start
Any Help/Suggestion Much Appreciated.
Kindly,
Assif
Hi,
You would like to have these API calls async instead of the synchronized way you have it now in the OnIntialize.
The OnInitialize is not the proper event to do this.
To do this, do a rightmouse click on your screen and choose "Fetch data from other sources" for each API seperatable.
Further optimization could be to have each tab to contain a webblock, and in the webblock do the "Fetch data from other sources" for the specific api.
Regards,
Daniel
Daniël Kuhlmann wrote:
You mean,
"Fetch data from other sources" will handle multiple call in a Async way.
And For each API If i created "Fetch data from other sources" hook , So how/where to call it on screen ?
Can u specify a sample guide to Consume a REST API with "Fetch data from other sources".
Thanks
Hi assif_tiger,
This is how you can call one of your REST APIs asynchronously. If you want to call all four of them, you repeat the process four times, calling one single REST API from each of them.
These will behave like if they where Aggregates, their outputs can be bound to your screen widgets and patterns. Once the call finishes, if the outputs are being used on any screen element, they will automatically be refreshed. If you need to do some processing on the results before the screen is re-rendered, you can handle the Data Action's OnAfterFetch event.
Jorge Martins wrote:
How can I give the Data of REST API to my List Aggregate under "Fetch data from other sources" ?
assif_tiger wrote:
You assign the output of your REST API call to the output of your Data Action.
I created 4 different "Fetch data from other sources" Actions, Now How could I call them async.
Like Daniël said, by defining a Data Action, you are telling the platform to call it asynchronously. If you define 4 different Data Actions they will each be called asynchronously and concurrently.
I added a JS block & call all the Client API action defined using JS.
All the 4 API are getting called at a same time.
Is it the right way ?
If I call them in OnInitialize then hey will be executed 1 by 1
If I use the JS to do so, then My previous approach is better, Where I created 4 diffrent action for API & called them via JS.
If you created them they (Fetch from other datasource) will be called automatically, you do not need to do anything for it.
Please read https://success.outsystems.com/Documentation/10/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events