15
Views
3
Comments
Solved
Customize consumed REST URLs
Question

Hi all,

I went to most of the referred to posts for this topic, but still found no answer to my question...

To give you some context, the team builds an internal tool to perform some functional tests implying multiple REST calls - each call's response becoming part of the next call request. OK, this just works fine.

But my concern is about environments, and so about customization of the endpoints.

In Outsystems, we have just one DEVTST environment. But, the called API's are defined in multiple DEVTST environments (we use 5 of them : DT1-DT2-DT3-DT5-DT7).

And the base URL's are thus defined as :

http://xxxxx-xxxxx-operational-xxxxx-dt1.apps.cntcl.mycompany.be

http://xxxxx-xxxxx-operational-xxxxx-dt2.apps.cntcl.mycompany.be

http://xxxxx-xxxxx-operational-xxxxx-dt3.apps.cntcl.mycompany.be

http://xxxxx-xxxxx-operational-xxxxx-dt5.apps.cntcl.mycompany.be

http://xxxxx-xxxxx-operational-xxxxx-dt7.apps.cntcl.mycompany.be

Of course, if I define each call, everthing works fine then, but a lot of things need to be duplicated, which doesn't seem so nice in terms of maintainibility.

I' could set up an alternate solution using the ESG - but everyone here would prefer an Outsystems solution.

Is understand I can customize the URL path as I want or use any variable in the call header ; I also understand that I can customize the base URL at run time - but for one environment...

What I would like is a possibility to replace dt1, dt2... by some kind of a variable to prevent such duplication I now have to do.

Does anyone could tell me if such a thing is possible (an, if so, how to ?)

Thanks in advance,

KR,

Michel.

Rank: #274
Solution

That's indeed how to do it. The only drawback is that you are without a context in that OnBeforeRequest. So you might need to add an extra parameter in your call (that gets ignored by the service itself) for you to identify in the OnBeforeRequest to which URL you want to go.

If I understand your question you want to set the base URL at runtime potentially differently on each call, is that correct?

If so you can define an OnBeforeRerquest event for the REST call


Then you can override the CustomizedRequest properties and change the URL any way you like. You just need to build in some checking to be able to tell which URL to change it to


Rank: #274
Solution

That's indeed how to do it. The only drawback is that you are without a context in that OnBeforeRequest. So you might need to add an extra parameter in your call (that gets ignored by the service itself) for you to identify in the OnBeforeRequest to which URL you want to go.

Rank: #3977

Great !

I wasn't aware of this Request structure behind the onBefore...

Makes my life much easier...

Thanks all.