{{Mark|Introduced with Version 8.4}}: <code>%rest:single</code> annotation.
In common many RESTXQ search scenarios, functions are defined for processing browser input is processed, and returning search resultsare returned. User experience can generally be made more interactive if a an updated search request 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 If the same function will be called for the second time, a the already running instance query will be stopped, and the HTTP error code {{Code|410}} (Gone) will be returned instead of the result:
<pre class="brush:xquery">
(: If fast enough, returns the result. Otherwise, if called again, raises 410 :)
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]
</pre>
By specifying a string along with the annotation, functions can be bundledtogether, and one request can be canceled by calling another one:. This is shown by another example, in which the first function can be interrupted by the second one. If you call both functions in separate browser tabs, you will note that the first tab will return <code>410</code>, and the second one will return <xml>stopped</xml>.
<pre class="brush:xquery">
%rest:single("EXPENSIVE")
function local:stop() {
<htmlxml>interruptedstopped</htmlxml>
};
</pre>
The following things should be noted: * If a query will be canceled, there will be no undesirable side-effects. For example, it won’t be possible to kill a query if it is currenly updating the database or perfoming any other I/O operations. As a result, the termination of a running query can take some more time as expected.* The currently executed function is bound to the client current session. This way, it can be ensured that one a 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, in which returns the initial session data was returned to the client.