Changes

Jump to navigation Jump to search
468 bytes added ,  12:48, 25 February 2021
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. In addition, XQuery modules that cannot be parsed will be ignored if {{Option|RESTXQERRORS}} is enabled.
To speed up processing, the functions of the existing XQuery modules are automatically cached in main memory:
=Error Handling=
==Raise Errors=={{Mark|Updated with BaseX 9.5:}} Status code {{Code|400}} changed to {{Code|500}}; omit stack trace. If an error is raised when RESTXQ code is parsed, compiled or evaluated, an HTTP response with the status code 500 is generated. By default, all server-side errors will be passed on to the client. This is particularly helpful during the development process. In a productive environment, however, it is advisable not to expose errors to the client. This can be realized via the {{Option|RESTXQERRORS}} option. If disabled, * XQuery modules that cannot be parsed will be ignored and* full error messages and stack traces will be suppressed and not included in the HTTP response.
{{Mark|Updated with BaseX 9.5:}} Status code {{Code|400}} changed to {{Code|500}}The full error information can still be looked up in the database logs.
If an error is raised during the evaluation of a RESTXQ function, an HTTP response with the status code 500 is generated. The response body contains the full error message and stack trace unless {{Option|RESTXQERRORS}} is disabled.==Raise Errors==
With the {{Function|Web|web:error}} function, you can abort query evaluation and , enforce a premature HTTP response with and report errors back to the supplied status code and response body text (and no stack trace)client:
<syntaxhighlight lang="xquery">
};
</syntaxhighlight>
 
In contrast to the standard <code>fn:error</code> function, a status code can be supplied, and the response body will only contain the specified error message and no stack trace.
==Catch XQuery Errors==
XQuery runtime errors can be processed via ''error annotations''.Error annotations have one or more arguments, which represent the error codes to be caught.The codes equal the names of the XQuery 3.0 [[XQuery 3.0#Try.2FCatch|try/catch]] construct:
{| class="wikitable"
=Changelog=
;Version 9.35* Updated: [[#Raise Errors|Raise Errors]]: Status code {{Code|400}} changed to {{Code|500}}, omit stack trace.
;Version 9.3
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu