===Content Negotiation===
Two following annotations Functions can be used to restrict functions restricted to specific content typesMedia Types:
* '''HTTP Content Types''': A function will only be invoked if the HTTP {{Code|Content-Type}} header of the request matches one of the given content types. Example:<syntaxhighlight lang="xquery">%rest:consumes("application/xml", "text/xml")</syntaxhighlight>* '''HTTP Accept''': A function will only be invoked if the HTTP {{Code|Accept}} header of the request matches one of the defined content types. Example:<syntaxhighlight lang="xquery">%rest:produces("application/atom+xml")</syntaxhighlight>==Consuming Data====
By defaultA function will only be taken into consideration if the HTTP {{Code|Content-Type}} header of the request matches one of the given types: <syntaxhighlight lang="xquery">declare %rest:path("/xml") %rest:consumes("application/xml") %rest:consumes("text/xml")function page:xml() { <xml/> };</syntaxhighlight> ====Producing Data==== A function will only be chosen if the HTTP {{Code|Accept}} header of the request matches one of the given types: <syntaxhighlight lang="xquery">declare %rest:path("/xml") %rest:produces("application/xml", both content "text/xml")function page:xml() { <xml/> };</syntaxhighlight> Multiple types can either be specified by a single or by multiple annotations. If no annotations are specified, {{Code|*/*}}is the default type. Note that the annotations will ''not'' affect the type of the actual response: You will need to supply an additional <code>[[#Output|%output:media-type]]</code> annotation or (if a single function may produce results of different types) generate an apt [[#Custom_Response|Custom Response]]. ====Quality Factors==== A client can supply quality factors supplied by a client will also be considered in to influence the path server-side function selection process. If a client supplies sends the following accept header…HTTP header with quality factors…
<syntaxhighlight>
Accept: */*;q=0.5,text/html;q=1.0</syntaxhighlight> …and if two RESTXQ functions exist for the addressed path with two different annotations for producing data… <syntaxhighlight lang="xquery">declare function %rest:produces("text/html") ......declare function %rest:produces("*/*") ...
</syntaxhighlight>
…and if two RESTXQ functions exist with the same {{Code|path}} annotation, one with the {{Code|produces}} annotation <code>*/*</code>, and another with <code>text/html</code>, the second …the first of these function will be calledchosen, because as the quality factor for <code>text/html</code> documents is highest.
Server-side As we cannot ensure that the client may supply quality factors are supported as well: If multiple function candidates are left over after the above steps, the selection process can also be controlled server-side. The <code>qs</code> parameter will can be consideredattached server-side to the Media Type. The function If multiple functions are left in the selection process, the one with the highest quality factor will be favored:
<syntaxhighlight lang="xquery">
declare function %rest:produces("textapplication/htmljson;qs=1")......declare function %rest:produces("*/*;qs=0.85")...
</syntaxhighlight>
Note that the annotation will ''not'' affect the content type of the actual response. You will need to supply an additional <code>[[#Output|%output:media-type]]</code> annotation.
===HTTP Methods===