Changes

Jump to navigation Jump to search
205 bytes removed ,  06:50, 29 November 2019
All RESTXQ [[XQuery 3.0#Annotations|annotations]] are assigned to the <code><nowiki>http://exquery.org/ns/restxq</nowiki></code> namespace, which is statically bound to the {{Code|rest}} prefix. A ''Resource Function'' is an XQuery function that has been marked up with RESTXQ annotations. When an HTTP request comes in, a resource function will be invoked that matches the constraints indicated by its annotations.
If a RESTXQ URL is requested, the {{Option|RESTXQPATH}} module directory and its sub-directories will be traversed, and all [[XQuery Extensions#Suffixes|XQuery files]] will be parsed for functions with RESTXQ annotations. Sub-directories that include an {{Code|.ignore}} file will be skipped. With {{Version|9.2}}In addition, XQuery modules that cannot be parsed will be ignored as wellif {{Option|RESTXQERRORS}} is enabled.
To speed up processing, the functions of the existing XQuery modules are automatically cached in main memory:
==Forwards and Redirects==
The two XML elements <code>rest:forward</code> and <code>rest:redirect</code> can be used in the context of [[Web Application]]s, precisely in the context of RESTXQ. These nodes allow e.g. multiple [[XQuery Update]]s in a row by redirecting to the RESTXQ path of updating functions. Both wrap a URL to a RESTXQ path. The wrapped URL should be properly encoded via <code>fn:encode-for-uri()</code>.===Redirects===
Note that, currently, these elements are not part of RESTXQ specification{{Mark|Removed with Version 9.3:}} {{Code|rest:redirect}} element.
===restThe server can invite the client (e.g., the web browser) to make a second request to another URL by sending a 302 response:forward===
Usage: wrap the location as follows<pre class="brush:xml"><rest:forwardresponse>{ $ <http:response status="302"> <http:header name="Location" value="new-location }"/> </http:response></rest:forwardresponse></pre>
This results in The convenience function {{Function|Web|web:redirect}} can be called to create such a server-side forwarding, which as well reduces traffic among client and server. A forwarding of this kind will not change the URL seen from the client's perspectiveresponse.
As an exampleIn the XQuery context, returning<pre class="brush:xml"><rest:forward>/hello/universe</rest:forward></pre>would internally forward redirects are particularly helpful if [[XQuery Update|Updates]] are performed. An updating request may send a redirect to http://localhosta second function that generates a success message, or evaluates an updated database:8984/hello/universe
<pre class==="brush:xquery">declare %updating %rest:path('/app/init') function local:create() { db:create('app', <root/>, 'root.xml'), db:output(web:redirect===('/app/ok'))};
The declare %rest:path('/app/ok') function <code>[[Web Module#weblocal:ok() { 'Stored documents:redirect' ||webcount(db:redirect]]open('app'))};</codepre> can be used to create a redirect response element. Alternatively, the following element can be sent:
<pre class="brush:xml"><rest:redirect>{ $location }</rest:redirect></pre>==Forwards===
A server-side redirect is called forwarding. It is an abbreviation forreduces traffic among client and server, and the forwarding will not change the URL seen from the client’s perspective:
<pre class="brush:xml">
<rest:responseforward> <http:response status="302"> <http:header name="location" value="{ $new-location }"/> </http:response></rest:responseforward>
</pre>
The client decides whether to follow this redirection. Browsers usually will, tools like [http://curl.haxx.se/ curl] won’t unless fragment can also be created with the convenience function {{CodeFunction|-LWeb|web:forward}} is specified.
==Output==
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu