Changes

Jump to navigation Jump to search
50 bytes added ,  23:41, 21 August 2012
no edit summary
=Module Declarations=
A All RESTXQ module needs to contain a declaration [[XQuery 3.0#Annotations|Annotations]] are assigned to the namespace {{Code|http://exquery.org/ns/restxq}}namespace, which is statically bound to the {{Code|restxq}} prefix. A ''Resource Function'' is an XQuery function that has been marked up with RESTXQ annotations (annotations will be introduced with the upcoming [[XQuery 3.0]] standard). When an HTTP request comes in, a resource function will be invoked that matches the constraints indicated by its annotations.
All files with extension {{Code|*.xqm}}, placed inside the directory specified by {{Code|HTTPPATH}} (refer to [[Web Application#Configuring Database Access|HTTP Server Configuration]]) will be treated as RESTXQ modules. These will be parsed for RESTXQ annotations and cached. If a module is modified, it will be parsed again at runtime.
declare namespace rest = 'http://exquery.org/ns/restxq';
declare %restrestxq:path("hello/{$world}") %restrestxq:GET %restrestxq:header-param("User-Agent", "{$agent}")
function page:hello($world as xs:string, $agent as xs:string*) {
<response>
<pre class="brush:xquery">
declare %restrestxq:path("form/") %restrestxq:POST %restrestxq:form-param("content","{$message}", "'no message delivered'")
function page:hello-postman($message as xs:string) {
&lt;response>
<pre class="brush:xquery">
declare %restrestxq:path("/a/path/{$with}/some/{$variable}")
function page:test($with, $variable as xs:integer) { ... };
</pre>
<pre class="brush:xquery">
declare %restrestxq:GET %restrestxq:POST %restrestxq:path("")
function page:root() { <html/> };
</pre>
<pre class="brush:xquery">
declare %restrestxq:PUT("{$data}") %restrestxq:path("")
function page:put($data) { "Data: " || $data };
</pre>
* '''HTTP Content Types''': a function will only be invoked if the HTTP {{Code|Content-Type}} header of the request matches one of the given mime types. Example:
<pre class="brush:xquery">%restrestxq:consumes("application/xml", "text/xml")</pre>
* '''HTTP Accept''': a function will only be invoked if the HTTP {{Code|Accept}} header of the request matches one of the defined mime types. Example:
<pre class="brush:xquery">%restrestxq:produces("application/atom+xml")</pre>
By default, both mime types are {{Code|*/*}}.
<pre class="brush:xquery">
%restrestxq:query-param("parameter", "{$value}", "default")%restrestxq:query-param("answer", "{$answer}", 42, 43, 44)%restrestxq:query-param("search", "{$search-param}")
</pre>
<pre class="brush:xquery">
%restrestxq:form-param("parameter", "{$value}", "default")
</pre>
<pre class="brush:xquery">
%restrestxq:header-param("User-Agent","{$user-agent}")%restrestxq:header-param("Referer","{$referer}", "none")
</pre>
<pre class="brush:xquery">
%restrestxq:cookie-param("username","{$user}")%restrestxq:cookie-param("authentication","{$auth}", "no_auth")
</pre>
import module namespace request = "http://exquery.org/ns/restxq/Request";
declare
%restrestxq:path("/id") %restrestxq:request("{$req}")
function page:id($req) {
request:session-id($req)
<pre class="brush:xquery">
declare %output:media-type("text/plain") %restrestxq:path("")
function page:kiss() { 'keep it simple, stupid' };
</pre>
<pre class="brush:xquery">
declare
%restrestxq:path("")
%output:method("xhtml")
%output:omit-xml-declaration("no")
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu