Database Reference
In-Depth Information
URI paths may be much more complicated and have several templates within them;
for example:
% rest:path ( "/country/{$country-code}/organization/{$org-id}/person/{$person-id}" )
Consumes constraint annotation
A resource function may be constrained by the media types of HTTP requests that it
is willing to process. You can achieve this by using one or more consumes constraint
annotations , %rest:consumes (see Example 9-8 ). If no consumes constraint annota‐
tions are present on a resource function, then the function is assumed to process all
content types. Consumes constraint annotations make the most sense in the context
of POST and PUT requests, where you wish to control the POST ed/ PUT ed resources that
your resource function processes. A consumes annotation is compared against the
Content-Type header from an incoming HTTP request.
Example 9-8. Resource function restricting request processing by Content-Type
xquery version "3.0";
module namespace ex = "http://example/restxq/5";
import module namespace rest = "http://exquery.org/ns/restxq";
declare
%rest:POST("{$body}")
%rest:consumes("application/xml", "text/xml")
function ex:echo($body) {
<received>{$body}</received>
};
We declare that we wish to only process incoming HTTP requests that have a
Content-Type of either application/xml or text/xml . You may specify as many
media types as you wish within a consumes constraint annotation, or use multi‐
ple consumes constraint annotations.
Produces constraint annotation
The produces constraint annotation , %rest:produces (see Example 9-9 ), is the
counterpart to the consumes constraint annotation: a resource function may be con‐
strained by the media types that a client is willing to accept in an HTTP response. If
no produces constraint annotations are present on a resource function, then the
function is assumed to create a response that is compatible with any client. Produces
constraint annotations are used for content negotiation scenarios, where the client
informs the server which media types it accepts. A produces constraint annotation is
compared against the Accept header from an incoming HTTP request.
Search WWH ::




Custom Search