All files with extension {{Mono|*.xqm}}, placed inside the {{Mono|HTTPPATH}} (refer to [[BaseX Web Application|HTTP Server Configuration]]) will be treated as RESTXQ modules. These will searched for matching RESTXQ annotations on each HTTP request.
A simple RESTXQ module is shown below, it is part of a clean installation and avaliable at http://localhost:8984/restxq/ .
<pre class="brush:xquery">(:~ A simple simplified module with REST-annotations as in http/restxq.xqm :)module namespace hw page = 'http://basex.org/modules/web-page';declare namespace rest = 'http://exquery.org/ns/restxq'; declare %rest:path("hello/{$world}") %rest:GET %rest:header-demo'param("User-Agent", "{$agent}")function page:hello($world as xs:string, $agent as xs:string) { <response> <title>Hello { $world }!</title> <info>You requested this page with { $agent }.</info> </response>};</pre> If the URI http://localhost:8984/restxq/hello/world is accessed, the result will be kind of
declare namespace rest <pre class= 'http"brush:xml"><response> <title>Hello world!</title> <info>You requested this page with Mozilla/exquery5.0 (Windows; U; Windows NT 5.org1; en-US) AppleWebKit/ns525.13 (KHTML, like Gecko) Chrome/restxq'0.2.149.27 Safari/525.13.</info></response></pre>
declare %restWe added another method within that module:path("{$path}") %output:media-type("application/xml")function hw:demo($path as xs:string) { <xml> Hello World! You accessed the path { $path }. </xml>};</pre>
If the URI <pre class="brush:xml">declare %rest:path("hello/{$world}") %rest:POST %rest:form-param("content","{Mono|http$post-content}") function page://localhosthello-postman($world as xs:8984string, $post-content as document-node()) { <response> <title>Hello { $world }!</restxq/demotitle> <info>It seems you posted a message { $post-modulecontent }.</info> </response>} is accessed, the result will be;</pre>
If you posted something (e.g. using curl or the embedded formular http://localhost:8984/restxq/ )<pre class="brush:shell">curl -i -X POST -H "content-type: application/xml" -d 'content="Here comes the post!"' 'http://admin:admin@localhost:8984/restxq/hello/mr-postman'</pre>You would recieve<pre class="brush:xml"><response> <xmltitle>Hello mr-postman!>lt;/title> Hello World<info>It seems you posted a message "Here comes the post! You accessed the path demo-module".</xmlinfo>>lt;/response></pre>
=Annotations=