Jump to content

Raw data endpoint


zilav
 Share

Recommended Posts

We already have a SendFile and ajaxRequest for additional data communication with server, but sometimes that's not enough. There are many js libraries out there that dynamically require some data (usually json), for example virtual scrolling lists and grids. The only way to do it now is to save a json file in LocalCache and provide url link to it.

What I need is some sort of event in MainModule, which is called when a request is made for some endpoint url. It needs to be able to pass url parameters (like onajaxrequest) and request's body as string (some js libs like to pass parameters via json and not in url), and sends back mime type (or even better custom html headers via TStrings) and data from TStream.

The endpoint url can be generated for each session with some uniGui method (in case it's implementation changes in future unigui versions), for example I call UniSession.GetEndpointURL, then add my additional url params to it, and give it to js library for it's ajax calls. If current session is active it fires event in MainModule, if session expires then just return empty response.

Link to comment
Share on other sites

No fixed format as all of them just make XHR to this url. Some of them add additional parameters to url, another pass them in request's body (as json, xml, etc). And some even leave sync methods on developer, you just need to provide a function which will accept some params and return data in array, or plain json.

So format doesn't matter. I just need an event called by manual XHR from client browser that can return raw data (header and body). And event should be unique for every session, thats why I proposed it's url to be generated by unigui.

 

Typical scenario - virtual scrolling grid with dynamically loaded data. In this demo it pulls json from this url (adding paging info to url directly)

 

var url = "http://services.digg.com/search/stories?query=" + searchstr + "&offset=" + (fromPage * PAGESIZE) + "&count=" + (((toPage - fromPage) * PAGESIZE) + PAGESIZE) + "&appkey=http://slickgrid.googlecode.com&tyape=javascript";

In my app I'll be pulling data from DB, so for example this base url "http://services.digg.com/search/stories?query=" should be generated by unigui, and I'll add my info to it.

But like I said some libs like to provide request param in request's body, so this method should be supported too.

 

p.s. Implementing this feature will truly open a vast possibilities of integrating hundreds of modern js libraries in unigui. I wouldn't even need ExtJS4 with it as everything will be possible to be made with 3d party tools inside UniHTMLFrame. :D

Link to comment
Share on other sites

  • Administrators

uniGUI data events has the following format:

 

/HandleEvent?IsEvent=1&Obj=O24&Evt=data&_S_ID=leA1AthqoO535aE

 

 

If you generate an equivalent event in same format it will be caught in Delphi OnAjaxEvent handler

 

S_ID is ID for current session.

 

Below function is defined in uniExtUtils.pas

 

function GetEventUrl(Obj: TExtObject; Event: string):string;

 

You can use it to generate a custom URL for a custom data request.

 

MyDataUrl := GetEventUrl(UniGUIControl.ExtControl, 'MyData'):

 

UniGUIControl is the Control which will handle the data request in its OnAjaxEvent event.

Link to comment
Share on other sites

Thanks, I see it is simple to generate a XHR call and pass my parameters, but how can I return a plain stream of data from this event?

Assuming that I caught this event, generated some json from DB, so what do I do to return that json as a plain string back to browser? I know I can AddJS() some code, but this will be eval()'d in javascript which is not good. And also I want to send back not only json, but sometimes a binary data, so eval() will just fail.

Does UniGUI have a similar function like AddString() or AddStream()?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...