562
Views
9
Comments
Solved
Best Approach for Calling multiple REST API in OnInitialize Action ?
Question

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





2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP
Solution

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

2021-04-09 11-42-43
assif_tiger
 
MVP

Daniël Kuhlmann wrote:

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

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


2019-09-24 18-41-25
Jorge Martins
 
MVP

Hi assif_tiger,


Daniël Kuhlmann wrote:

To do this, do a rightmouse click on your screen and choose "Fetch data from other sources" for each API seperatable.

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.

2021-04-09 11-42-43
assif_tiger
 
MVP

Jorge Martins wrote:

Hi assif_tiger,


Daniël Kuhlmann wrote:

To do this, do a rightmouse click on your screen and choose "Fetch data from other sources" for each API seperatable.

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.

How can I give the Data of REST API to my List Aggregate under "Fetch data from other sources" ?


2019-09-24 18-41-25
Jorge Martins
 
MVP

assif_tiger wrote:

How can I give the Data of REST API to my List Aggregate under "Fetch data from other sources" ?

You assign the output of your REST API call to the output of your Data Action.

assif_tiger wrote:

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.

2021-04-09 11-42-43
assif_tiger
 
MVP

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 ?

2021-04-09 11-42-43
assif_tiger
 
MVP

I created 4 different "Fetch data from other sources"  Actions, Now How could I call them async.

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.


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

If you created them they (Fetch from other datasource) will be called automatically, you do not need to do anything for it.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.