Skip to content

Instantly share code, notes, and snippets.

@joewiz
Created November 23, 2014 04:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewiz/28dd9b8454d14b4164a0 to your computer and use it in GitHub Desktop.
Save joewiz/28dd9b8454d14b4164a0 to your computer and use it in GitHub Desktop.
A starter template for a RestXQ module
xquery version "3.0";
module namespace my-app = "http://my/app";
(: A starter template for a RestXQ module.
Save this file into eXist anywhere (e.g., /db/restxq-template.xqm or /db/apps/my-app/modules/restxq-template.xqm),
And access at http://localhost:8080/exist/restxq/index.html.
(Why? Because /restxq is the URL space for RestXQ, and the function's %rest:path annotation is for requests to "/index.html".)
Note that the collection configuration file where you store the module must invoke the RestXQ trigger:
<collection xmlns="http://exist-db.org/collection-config/1.0">
<triggers>
<trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
</triggers>
</collection>
But this should already be in place, since /db/system/config/db/collection.xconf will apply to any collection
unless overridden by another collection.xconf file.
:)
declare namespace rest = "http://exquery.org/ns/restxq";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare
%rest:GET
%rest:path("/index.html")
%output:media-type("text/html")
%output:method("html5")
function my-app:hello() {
let $title := 'Hello world!'
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$title}</title>
</head>
<body>
<h1>{$title}</h1>
</body>
</html>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment