exist-dbrestxq

How to register RESTXQ module in eXist-db?


I am trying to use RESTXQ in my exist-db application - lets call it "superapp". I added the restxq trigger to /db/apps/superapp/collection.xconf:

<collection xmlns="http://exist-db.org/collection-config/1.0">
    <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <fulltext default="none" attributes="false"/>
    </index>
    <triggers>
        <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
    </triggers>
</collection>

Then I added a file "restxq-test.xql" to the folder /db/apps/superapp/modules:

xquery version "3.0";

module namespace test="http://exist-db.org/apps/restxq/test";


declare namespace rest="http://exquery.org/ns/restxq";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";


declare
    %rest:GET
    %rest:path("/super")
    %output:media-type("text/html")
    %output:method("html5")
    %rest:query-param("user", "{$user}", "Guest")
function test:hello($user as xs:string*) {
    let $title := 'Hello '
    return
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>{$title}</title>
            </head>
            <body>
                <h1>{$title , $user}</h1>
            </body>
        </html>
};

But how do I make restxq "know" that this new module is there? It obviously does not do so automatically. If I call "xyz.com:8080/exist/restxq/super?user=John" I get

HTTP ERROR 405

Problem accessing /exist/restxq/super. Reason:

    HTTP method GET is not supported by this URL

I restarted eXist and I checked /var/www/exist/webapp/WEB-INF/logs/restxq.log but there is no entry in there... I'm quite sure the function and attribute mapping is correct. If I add the same function to "/db/apps/demo/examples/templating/restxq-demo.xql" (which is obviously registered) it works just perfect. So I guess the new module is just not registered. How can I do that?


Solution

  • I would post a comment, but I don't have enough points. I am not sure if this is going to solve your whole issue with the RESTXQ because I have not used it in my application, but it seems that you have placed collection.xconf file in the wrong collection. It should be placed in the system collection: /db/system/config. That means that your configuration file should be in /db/system/config/db/apps/superapp collection. More info on triggers you have on the exist-db website on the documentation page: Configuring Database Triggers