</pre>
=Response= By default, a successful request is answered with the HTTP status code {{Code|200}} (OK), and is followed by the given content; an erroneous request leads to an error code and an optional error message (e.g. {{Code|404}} for “resource not found”). Custom responses can be built from within XQuery by returning an <code>rest:response</code>, an <code>http:response</code> child node that matches the syntax of the [http://expath.org/spec/http-client EXPath HTTP Client Module] specification, and more optional child nodes that will be serialized as usual. E.g. one may return to the client <pre class="brush:xml"><rest:response> <http:response status="404" message="I was not found."> <http:header name="Content-Language" value="en"/> <http:header name="Content-Type" value="text/html; charset=utf-8"/> </http:response></rest:response></pre> =Output==
Similar to the [[REST#Content Type|REST]] interface, result serialization can be modified via [[XQuery 3.0#Serialization|XQuery 3.0 serialization parameters]]; in RESTXQ, serialization parameters may be specified in the query prolog, via annotations, or within REST response element. Global parameters are overwritten by more local parameters.
===Query Prolog===
In main modules, serialization parameters may be specified in the query prolog. These parameters will then apply to all functions in a module. In the following example, the content type of the response is overwritten with the {{Code|media-type}} parameter:
</pre>
===Annotations===
The serialization can also be parameterized via annotations:
</pre>
===Response Element===
The following example demonstrates how serialization parameters can be dynamically set within a query:
</pre>
==Error Handling==
{{Mark|Introduced with Version 7.7:}}
'Remote host name: ' || request:remote-hostname()
};
</pre>
=Response=
By default, a successful request is answered with the HTTP status code {{Code|200}} (OK), and is followed by the given content; an erroneous request leads to an error code and an optional error message (e.g. {{Code|404}} for “resource not found”).
Custom responses can be built from within XQuery by returning an <code>rest:response</code>, an <code>http:response</code> child node that matches the syntax of the [http://expath.org/spec/http-client EXPath HTTP Client Module] specification, and more optional child nodes that will be serialized as usual. E.g. one may return to the client
<pre class="brush:xml">
<rest:response>
<http:response status="404" message="I was not found.">
<http:header name="Content-Language" value="en"/>
<http:header name="Content-Type" value="text/html; charset=utf-8"/>
</http:response>
</rest:response>
</pre>