Changes

Jump to navigation Jump to search
1,921 bytes added ,  09:09, 7 February 2016
no edit summary
HTTP responses.
Please note that BaseX provides various extensions to the official original draft of the specification:
* Multipart types are supported, including {{Code|multipart/form-data}}
* Quality factors in the [[#Content Negotiation|Accept header]] will be evaluated
* <code>%input</code> annotations, support for input-specific content-type parameters
* Since {{Version 8.4}}: <code>%rest:single</code> annotation to cancel running RESTXQ functions
<br />
%rest:cookie-param("authentication", "{$auth}", "no_auth")
</pre>
 
==Query Execution==
 
{{Mark|Introduced with Version 8.4}}: <code>%rest:single</code> annotation.
 
In common RESTXQ scenarios, functions are defined for processing browser input and returning search results. User experience can be made more interactive if a search is triggered with each key click. However, such search patterns may lead to numerous parallel requests, from which only the result of the last request will be relevant for the client.
 
With the <code>%rest:single</code> annotation, it can be enforced that only one instance of a function will be executed for the same client. As soon as the function will be called for the second time, a running instance will be stopped, and the HTTP error code {{Code|410}} (Gone) will be returned instead of the result:
 
<pre class="brush:xquery">
declare
%rest:path("/search")
%rest:query-param("term", "{$term}")
%rest:single
function page:search($term as xs:string)
{
<ul>{
for $result in db:open('large-db')//*[text() = $term]
return <li>{ $result }</li>
}</ul>
};
</pre>
 
By specifying a string along with the annotation, functions can be bundled, and one request can be canceled by calling another one:
 
<pre class="brush:xquery">
declare
%rest:path("/compute")
%rest:single("EXPENSIVE")
function local:compute() {
(1 to 100000000000000)[. = 0]
};
 
declare
%rest:path("/stop")
%rest:single("EXPENSIVE")
function local:stop() {
<html>interrupted</html>
};
</pre>
 
The currently executed function is bound to the client session. This way, it can be ensured that one client will not be able to cancel requests from other clients. As a result, functions can only be stopped if there was at least one previous successful response, which returns the session data to the client.
=Response=
=Changelog=
 
;Version 8.4
 
* Added: <code>%rest:single</code> annotation
;Version 8.1
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu