WebSDK2 HandleRequest

Hi there,

I’m in the process to wrap some third party controls.
The grid control I’m using can automatically fetch data from a url. So I wan’t to provide the data through an embedded api.

I read about the “HandleRequest(Request as WebRequest, Response as WebResponse) As Boolean” event in the sdk which seems to fit exactly my needs.

So I’m setting the rest url of my grid to the following: window.location.href + "/sdk/" + this.controlID()
The request arrives correctly BUT not inside the HandleRequest event of the control. But inside the HandleUrl event of the app.

I’m not handling anything in the HandleUrl event. So it should be routed to my control.

Please can someone push me into the right direction?


Hi Daniel,

Within the class that extends XojoWeb.XojoVisualControl in the updateControl method try something like:

let el = this.DOMElement();
 if (!el)
     const url = window.location.protocol + '//' + window.location.host + '/sdk/' + el.id + '/Request';

NB: If you add your control via .AddControl there is a bug that does not allow you to call HandleRequest. You have to necessarily add it via IDE.

Thank you Attilio,

I think I puzzled it down.
You can use the following javascript to build a correct url XojoWeb.SessionURL() + "/data/" + this.ControlID()
Keep in mind you have to use “data” and not “sdk” in the path. I you use “sdk” the request is not arriving the control.

@Xojo Please update the documentation for the WebSDK.
I think this Tool is awesome and we could do amazing things with a good SDK. But the lack of documentation/examples is awful.

I have always used /sdk/ and it has always worked. If you open the example attached to the feedback case you can verify that it works. (I did not put the js code in the class but in the show event, but nothing changes).

If you replace /sdk/ with /data/ in that project it no longer works.

So I figured it out.
Another rule learned (should be placed in the documentation!! @Xojo )

I used a absolute url with the XojoWeb.SessionURL() + “/sdk” + this.ControlID().
That’s wrong.
Using a relative url like “/sdk/” + this.ControlID() it’s working.

Thank you @Attilio_Punzi

1 Like

@Daniel_Hüttenberger Glad to have been helpful :wink: