Topic
3 replies Latest Post - ‏2012-12-06T20:45:47Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts
ACCEPTED ANSWER

Pinned topic WL Adapter as JSON, REST Server

‏2012-12-05T21:09:25Z |
My apologies in advance if I've overlooked an obvious answer.

I want to create Worklight adapters that communicate to Dojo widgets using JSON and REST rather than using invokeProcedure(). Some Dojo widgets handle JSON natively and I think this will make my app more maintainable and let me push more logic into the adapter. Furthermore, I'd like the option to have other UIs (like full Objective C apps) to communicate with the adapter.

What's the best way to do this? Can it be done?
  • SystemAdmin
    SystemAdmin
    2327 Posts
    ACCEPTED ANSWER

    Re: WL Adapter as JSON, REST Server

    ‏2012-12-06T05:49:22Z  in response to SystemAdmin
    There are two ways to call adapters that I'm aware of:
    1. Using invokeProcedure()
    2. Using the URL:
    
    http:
    //localhost:8080/invoke?adapter=customers&procedure=getCustomers&parameters=[]
    

    Where localhost is the server running the Worklight Server, customers is the adapter name, getCustomers is the procedure name and parameters are any parameters you want to pass to the procedure.

    Taken from my post here: http://www.ibm.com/developerworks/forums/message.jspa?messageID=14893550#14893550

    I'm not sure about your dojo specific questions, but if you can't use invokeProcedure or the URL you probably can't do it with Adapters.
    • Eric Durocher
      Eric Durocher
      38 Posts
      ACCEPTED ANSWER

      Re: WL Adapter as JSON, REST Server

      ‏2012-12-06T09:16:50Z  in response to SystemAdmin
      Hi,

      I am not sure what the Dojo side of the question is, but as general guidelines, as soon as the WL adapter returns JSON data, you can use the appropriate Dojo data store to plug that data to any Dojo data-aware widget:

      • If the widget supports "old-style" dojo/data stores, you can use either a simple dojo/data/ItemFileReadStore or more advanced stores like dojox/data/QueryReadStore or dojox/data/JsonRestStore

      • If the widget supports "new-tyle" dojo/store, you can use a dojo/store/JsonRest store.

      If you are using Dojo Mobile widgets, there are variants that support both stores (old a new), so you should go for new (e.g. EdgeToEdgeStoreList + dojo/store/JsonRest). You will find examples of this on dojox/mobile/tests (test_EdgeToEdgeStoreList.html, etc).

      Hope that answers the question...?

      Eric
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: WL Adapter as JSON, REST Server

        ‏2012-12-06T20:45:47Z  in response to Eric Durocher
        Perfect. Thanks to both of you for your answers.