Database Reference
In-Depth Information
Example 9-9. Resource function restricting request processing by Accept
xquery version "3.0" ;
module namespace ex = "http://example/restxq/6" ;
import module namespace rest = "http://exquery.org/ns/restxq" ;
declare
%rest:POST ( "{$body}" )
%rest:consumes ( "application/xml" , "text/xml" )
%rest:produces ( "application/xml" )
function ex:echo( $ body ) {
<received> { $ body } </received>
};
We declare that we wish to only process incoming HTTP requests that will
accept a response of type application/xml . You may specify as many media
types as you wish within a produces constraint annotation, or use multiple pro‐
duces constraint annotations.
Parameter annotations
RESTXQ provides four different parameter annotations; however, their behavior is
almost identical. It is the source of the parameter extraction that is the main differ‐
ence. The annotations are:
Query parameters
%rest:query-param extracts a parameter from the URI query string of the HTTP
request. The value extracted may be an empty sequence (if the parameter is not
present) or a sequence of one or more values, as it is possible to have URI query
parameters with the same name and different values.
Header parameters
%rest:header-param extracts a parameter from an HTTP header of the HTTP
request. The value extracted may be an empty sequence (if the header is not
present), or the value of the header.
Cookie parameters
%rest:cookie-param extracts a parameter from a cookie in the HTTP header of
the HTTP request. The value extracted may be an empty sequence (if the cookie
is not present), or the value of the cookie.
Form field parameters
%rest:form-param extracts a parameter from a POST ed or GET ed HTML form, so
this can only be used in combination with %rest:POST and/or %rest:GET . The
value extracted may be an empty sequence (if the form field is not present) or a
Search WWH ::




Custom Search