During LiveLink training this week it suddenly hit me that with very little effort at all one should be able to create a LiveLink request handler and instead of excreting HTML for end-user consumption instead send back dynamically generated XML (or CSV-formatted values, or JSON or text or whatever) using a minimum amount of programming on the LiveLink side except for some OScript in the Weblingo files.
Given that LiveLink's functionality is accessible via parameter driven URLs, this seemed like a great way to provide a RESTful like solution with "no code" (other than some OScript, but hey, that's not real code, right? :o). After some playing around I got it working and this post is meant to document how I did it, both for myself and for anyone who stumbles across this via search engines.
- Create a new Request Handler as normal.
- Populate the fHTMLFile feature, ensuring that it ends in .html.
- Set the fHTMLMimeType feature to text/xml, This is so the browser's GetXmlHttpObject will recognize the output as XML (change the MIME type accordingly if you are sending down CSV or other data formats).
- Override the Execute method to set some HTTP headers to ensure the returned content is seen as XML as shown below.
- Inside the WebLingo file for the Request Handler place your XML, a sample is shown below.
- Create a second Request Handler to consume our XML file as normal, a sample of the WebLingo is shown below, update it to ensure the url parameter points to your first Request Handler.
- Call the second Request Handler and you should see something like the following :
Sample WebLingo File 1 | Sample WebLingo File 2 |
---|---|
|
;System.BaselineRefCounts() LiveLink stats: |
Sample Execute Method | |
function Dynamic Execute(Dynamix ctxIn, Dynamic ctxOut, Record r) .fExtraHeaders ='Content-Distribution: attachment;filename=test.xml' + Web.CRLF; return undefined; end |