Reactive: retrieve data through api in web block, or once on screen?

Hi OutSystems community!

I have another question about Reactive Web app development.

In our app, we need to do a single API call, to retrieve a list of values.
This list will be used to give options inside a dropdown, inside of a web block, which is inside of a popup.

Now traditional best practice would be to do the call inside of the web block, because you want to get the data where you use it.

However, in this case, that would mean the API call is done multiple times (each time the popup is opened), while when I place this API call inside of the screen, it's only done once.
I would then pass the data on to the web block, using an input parameter for the web block.

What would be best here?

Thanks in advance :)


Hi Marleen,

Your if you are calling you API in prepration then it will be called only first time when model loads. Upon subsequent action it will just open the model again instead of reinitializing it.

Hi Nikhil,

Since it's React, the web block doesn't have a preparation, only an OnInitialize.
The OnInitialize runs each time the popup with web block is opened again,
So, if I place the API call in the OnInitialize, it will run each time I open the popup.

If I instead use a data action, it wil also run each time I open the popup (I've checked this, using the debugger, the data action is called each time the popup is set to 'visible' again).


Hi Marleen,

You are right, and the option to take depends. As it's often the case, there is a trade-off between maintainability of the code and performance. I would always start with code that is easier to read, unless I have proof or strong evidence that the potential performance problems will have a real impact on user experience (Donald Knuth, one of the greatest minds of computer science, says that premature optimization is the root of all evil).

Tiago Simões


Hi Tiago!

Thanks for your input, that makes a lot of sense.
Yeah, probably, since it's a simple API call, returning a list of about 10 strings and 10 integers, it should be fine.
I'll place the data action in the web block. If it creates performance issues later, we can always turn it back.

Have a good day!