We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20804
    • 5 Posts
    Hi yall smiley

    Anybody built a remote query api for ModX yet? Like REST, XML-RPC, CMIS or similar...
    Considered using DITTO, but my god! That snippet is sooooo tedious with its endless configs.

    So apart from DITTO, is there some neat "core service" i can use to get xml/json (xpdo perhaps...) from ModX?

    I am going to use this to make a template studio application. A WYSIWYG design studio made with Ext/JQuery. But i need a remote api to make it modular enough.

    Ciao,
    Lars
      • 22303 MODX Staff
      • 10,725 Posts
      There are a multitude of ways to build REST, XML-RPC, SOAP or other services with MODx, but the "API" to use depends on your actual requirements/needs. PHP has most of these "API’s" available already and MODx Resources can return any valid content-type, so building your services is similar to creating a site map; define which Resources do what in your web service definition, and simply write scripts to return the appropriate content your services expect (i.e. JSON, XML, etc.) from the appropriate Resource.

      I’m with you, Ditto is a great snippet for summarizing HTML Resources (and a few other things) but certainly not the right solution for defining a web service API.
        • 20804
        • 5 Posts
        My main hope here was that there was a ready-built ModX Core API to return, lets say, JSON.
        Maybe something like this,

        www.mymodx.com/assets/remoteapi/index.php?action=get&id=104&format=json
        www.mymodx.com/assets/remoteapi/index.php?action=put&id=104&format=json&object={name="foo",content="bar"}
        www.mymodx.com/assets/remoteapi/index.php?action=delete&id=104

        If this is not in the works, what would you suggest?

        Ciao,
        Lars
          • 22303 MODX Staff
          • 10,725 Posts
          You’re just over-thinking this. All you need to do is create a MODx Resource (i.e. a page) with the Content Type you are going to return, then define a snippet that takes your query string parameters for the actions and have it output or process (or whatever) the data based on those actions. If your results will use similar output, you can define a Template for the basic output and the Snippet call, or just use the blank Template (no template IOW) and call your Snippet in the Resource’s content.
            • 20804
            • 5 Posts
            I see what you mean. Thats why i like ModX, its every pragmatists dream smiley

            However, i think ModX needs a defined/solid way to communicate its objects using HTTP. I am very happy to see how the concepts of SOA are evolving within the CMS community, with projects like CMIS (http://en.wikipedia.org/wiki/Content_Management_Interoperability_Services) etc. I think the implementation of well defined RPC protocols are essential for all modern business systems, and one of the most important corner stones of any content-centric system specifically.

            For now I’ll make a module to configure a GET based XML-RPC protocol (XRPC?) for remote querying of ModX objects (Pages, Templates Chunks etc). This protocol will return JSON Objects wrapped in XML.
            I was happy to see that PHP5.2 has a feature to JSON encode/decode assoc. arrays on the fly smiley This will make it easy (i hope wink ) to layer the current "Document Object" and "DocumentParser Object".

            For a really cool implementation of SOA, and REST in particular, check out www.alfresco.com.

            If anyone wants to help, mezz me smiley

            Thnx,
            Lars
              • 22303 MODX Staff
              • 10,725 Posts
              Ok, I didn’t realize you were talking about MODx Core Content Management services; this is not something implemented at all in Evolution, but MODx Revolution’s Core CMS facilities have been developed in a structure that abstract all administration functions into core processors. The current implementation serves JSON required by ExtJS since the default manager UI is constructed with this framework. We are considering the best ways to make this same system of core processors usable from various other service implementations.

              If you’d like to collaborate on development of these, I would suggest getting involved with Revolution development and we can certainly discuss and coordinate any efforts in this regard.
                • 20804
                • 5 Posts
                He he smiley

                Seems like its going to be pretty easy! The json_encode function really rocks!
                In fact as it is i could just use the php eval function to call the core api using query string parameters. This is good from a structural point as it has minimum dependencies. Just have to consider security issues before doing any more coding...

                Looki looki example:

                print_r(json_encode($modx->getDocument(1)));

                This returns a perfect JSON Object string smiley

                Will make a Snippet first.

                Ciao
                  • 20804
                  • 5 Posts
                  Hi again smiley

                  I made my first CMS which was layered in this fashion around 2000 so i have quite a bit of experience in this field smiley

                  I have not have time to check out the Revolution Core yet. If i can help out in any way i will of course do so smiley

                  Let me browse through the docs...

                  Ciao,
                  Lars