RESTXQ functions by default will match regardless of the HTTP Method being used in the request. You can however restrict whether a function can execute or not based on the request's HTTP Method.
XQRS Supports the following HTTP Methods:
GET, HEAD, POST, PUT, DELETE, OPTIONS
and PATCH
.
To restrict a function to using a particular HTTP method add the
annotation to the function. Consider the following example
declare
%rest:path("/factory/warehouse/wheel/{$wheel-id}")
%rest:POST
function post-wheel($wheel-id as xs:integer) {
create-wheel($wheel-id)
};
declare
%rest:path("/factory/warehouse/wheel/{$wheel-id}")
%rest:GET
function get-wheel($wheel-id as xs:integer) {
retrieve-wheel($wheel-id)
};
In the above example, the post-wheel
function would
only be invoked for POST
requests to a URI like
/factory/warehouse/wheel/1234
.
Where as the get-wheel
function would only be invoked
if the Request was a GET
Request.
For simplicity's sake, you can add multiple HTTP Method annotations to a function, ensuring that it can only be invoked when the Request Method matches one of them.
In the following example, the get-or-post
function
could only be invoked if the HTTP Request method was of type
GET
or POST
declare
%rest:path("/generic/{$name}")
%rest:POST
%rest:GET
function get-or-post($name as xs:string) {
<hello>{$name}</hello>
};