How to use LocalEntity Data Value in onBeforeRequest in REST API

How to use LocalEntity Data Value in onBeforeRequest in REST API

  

Hi,

I am using OnBeforeRequest for Customizing baseURL for REST API based on Client ID.

I have Client-ID stored in my Local Entity. How can I pass that in onBeforeRequest, as of it is not allowing me to use Local-Entity or any Client Action.


Thanks

Hi Assif,

REST calls are made from the Server, not from the Client (they are therefore akin to Server Actions). You could wrap the REST call in a Server Action that has a parameter for the URL, and call that instead of the REST directly.

Hi Assif,


There is one possibility , But it will work only if we can call the client action from "RunJavascript",


Below is the procedure,


Create Entity Database which is corresponding to your local Client ID.

Create client Action and update the data in your main entity, Now data is available in  your server entity, you can take this data from your call back function.

Execute this client action from your callback function(if we can) using RunJavascript action.

And now you can use your server entity to take data(By Aggregate with proper filter)


Thanks,

Ramakrushna Rao Seera

Hi Ramakrushna,

I'm at loss what kind of solution you are proposing here. It doesn't seem to relate to Assif's question at all, and it also doesn't seem solid advise. Please, prefer quality over quantity!

Kilian Hekhuis wrote:

Hi Assif,

REST calls are made from the Server, not from the Client (they are therefore akin to Server Actions). You could wrap the REST call in a Server Action that has a parameter for the URL, and call that instead of the REST directly.

Thanks, Kilian

Actually, I am consuming third-party REST API & thus I have grouped all the API calls under one group where we define the base-URL.

On that, I have created an onBeforerequest Action where I am trying to change the base-URL at runtime so that I can use my application for multiple Host End-points.

The Approach was to achieve below post solution:

https://www.outsystems.com/forums/discussion/41212/how-to-give-dynamic-base-url-in-rest-api-mobile-app/





Hi Tiger,

# First, send the local entity (client) rows to server entity: see https://www.outsystems.com/forums/discussion/21881/local-data-to-server-database/

# Once in the server side, you should be able to read the server entity and use that: https://www.outsystems.com/forums/discussion/41212/how-to-give-dynamic-base-url-in-rest-api-mobile-app/

regards

@Box: that's also an unhelpful answer, and not much different from the bad answer Ramakrushna gave. Please read the entire topic before answering.

@Assif: well, there's no direct way of having a local client setting be transfered to the server for each call. So if your base URL depends on the client ID, you need to pass that client ID to the server. Note that one trick could be to add the client ID as a parameter to each REST Method, and make it part of the URL. In that way, you don't even need the OnBeforeRequest to modify the URL (assuming that the true base URL, minus the client ID part is the same for all clients).

On a related note, if the client ID makes the difference for end points between clients, make sure there's some security in place, and clients can't access the data of another client by just manipulating the URL!

One more thing: it's probably not a good idea to store client IDs only on the mobile device. I'd always syncrhonise such data with the server.

Solution

Kilian Hekhuis wrote:

@Box: that's also an unhelpful answer, and not much different from the bad answer Ramakrushna gave. Please read the entire topic before answering.

@Assif: well, there's no direct way of having a local client setting be transfered to the server for each call. So if your base URL depends on the client ID, you need to pass that client ID to the server. Note that one trick could be to add the client ID as a parameter to each REST Method, and make it part of the URL. In that way, you don't even need the OnBeforeRequest to modify the URL (assuming that the true base URL, minus the client ID part is the same for all clients).

On a related note, if the client ID makes the difference for end points between clients, make sure there's some security in place, and clients can't access the data of another client by just manipulating the URL!

One more thing: it's probably not a good idea to store client IDs only on the mobile device. I'd always syncrhonise such data with the server.

Hi Kelvin,

Thanks for the Quick Response & Kind Help :)

I resolved that by below approach:

I added InputVariable in Header to each REST API Method & than in onBeforeRequest I Iterate the Header Table & Assign it to CustomizeRequest-Base URL.

Now at Each REST API Method Call from Screen I am passing the Client Host to be used.

That Works... Perfectly



Thanks,

Assif

Solution