<pre class="brush:xquery">
declare %rest:path("/a/path/{$with}/some/{$variable}")
function localpage:test($with, $variable as xs:integer) { ... };
</pre>
<!-- TODO how matching works -->
<pre class="brush:xquery">
declare %rest:GET %rest:POST %rest:path("")
function localpage:root() { <html/> };
</pre>
<pre class="brush:xquery">
declare %rest:PUT("{$data}") %rest:path("")
function localpage:put($data) { "Data: " || $data };
</pre>
===Content TypesNegotiation===
Two additional annotations can be used to restrict functions to specific content types: * '''HTTP Content Types''': One or more mediaa function will only be invoked if the HTTP {{Mono|Content-Type}} header of the request matches one of the given mime types may be specified as strings, e.g.Example:<br/>
<pre class="brush:xquery">%rest:consumes("application/xml", "text/xml")</pre>
* '''HTTP Accept''': One or more media-a function will only be invoked if the HTTP {{Mono|Accept}} header of the request matches one of the defined mime types may be specified as strings, e.g.Example:<br/>
<pre class="brush:xquery">%rest:produces("application/atom+xml")</pre>
These By default to <code>, both mime types are {{Mono|*/*</code> if no media-type annotations are given}}.
==Parameters==
%rest:cookie-param("username","{$user}")
%rest:cookie-param("authentication","{$auth}", "no_auth")
</pre>
==Output==
By default, all results will be returned with content type {{Mono|application/xml}}.
Similar to our [[REST#Content Type|REST]] interface, result serialization can be modified via [[XQuery 3.0#Serialization|XQuery 3.0 serialization parameters]]. In RESTXQ, all parameters are specified within annotations.
The content type can be overwritten with the {{Mono|media-type}} annotation:
<pre class="brush:xquery">
declare %output:media-type("text/plain") %rest:path("")
function page:kiss() { 'keep it simple, stupid' };
</pre>
Next, the content type can also be overwritten by specifying an output {{Mono|method}}. The following method mappings are available:
#* <code>xml</code> → <code>application/xml</code>
#* <code>xhtml</code> → <code>text/html</code>
#* <code>html</code> → <code>text/html</code>
#* <code>text</code> → <code>text/plain</code>
#* <code>raw</code> → <code>application/octet-stream</code>
#* <code>json</code> or <code>jsonml</code> → <code>application/json</code>
The following example will use {{Mono|text/html}} as content type:
<pre class="brush:xquery">
declare
%rest:path("")
%output:method("xhtml")
%output:omit-xml-declaration("no")
%output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
%output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
function page:start() {
<html xmlns="http://www.w3.org/1999/xhtml">
<body>done</body>
</html>
};
</pre>