Results 1 to 1 of 1

Thread: Desktop web service API built into your Apps in Lianja v2

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,767

    Desktop web service API built into your Apps in Lianja v2

    Imagine...

    You have a desktop app that is running on user desktops.

    You want to somehow get information from the running app and return that information as JSON, XML or an HTML page.

    Well, in Lianja v2 you can.

    There is an simple http server built into your Lianja Apps that run under the App Center. By default this server listens on port 8002 but this is configurable (in the App settings) and handles asynchronous service requests while your App is running.

    So while an App is running, from another App you can query it e.g.:

    result = getURL("http://localhost:8002/desktopwebservice/library:/dws_getinfo?customerid=ALFI")

    The web service name follows /desktopwebservice/ in the URL and is a normal program or proc. In this case we have a script named dws_getinfo. It is good practice to name these consistently and place them in the library directory. I would recommend prefixing your desktop web services with dws_.

    Code:
    // In this example, the URL will contain "/desktopwebservice/library:/dws_getinfo" and args will contain "customerid=ALFI"
    // dws_getInfo.prg in the library directory
    private p_url
    private p_arg
    private p_args = explode("&", p_arg)
    private p_customerid = getMember("p_args", "customerid", "")
    return "{'url': '&p_url, 'customerid': '&p_customerid'}"
    Your service may return a JSON encoded object (as shown above), an XML string, an HTML string or plain text.

    If the result returned starts with "file:" then the file specified e.g. "file:mytempfile.txt" is read and the result is sent back to the client. This provides the ability to query large amounts of information not limited by internal string length.

    If the result returned starts with "tempfile:" then the file specified e.g. "tempfile:mytempfile.txt" is read and the result is sent back to the client. The file mytempfile.txt is then deleted.

    Notice that in the example above no file extension was given to dws_getinfo so ".prg" (Lianja/VFP script) is assumed. You could also specify:

    result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.js?customerid=ALFI")
    or
    result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.php?customerid=ALFI")
    or
    result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.py?customerid=ALFI")
    or
    result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.rsp?customerid=ALFI")
    or
    result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.jssp?customerid=ALFI")

    This is not designed to replace the Cloud Server which handles multiple concurrent requests but rather to provide a means of introspecting running apps and consolidating information from them.

    It is not difficult to see how you could use this to great effect with desktop LAN apps in a Web App that uses a .rsp page that queries information from the various clients running Lianja Apps.

    Tip: remember to use SAVE/RESTORE DATASESSION as these web service requests are handled asynchronously while your App is running.

    Tip: you could specify an apikey=value on the URI and the authenticity of the apikey will be verified when the desktop web service request is received. The API key is an attribute in the App settings. The default behavior is to service requests with no apikey authentication if none is specified for an app.
    Last edited by barrymavin; 2016-03-30 at 23:02.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us