Database Reference
In-Depth Information
sequence of one or more values, as it is possible to have form fields with the same
name and different values!
All of the parameter annotations have the same two forms:
%rest:source-param ( parameter-name , function-parameter-reference )
%rest:source-param ( parameter-name , function-parameter-reference,
default-value )
The second form allows you to specify a default value to be injected into the named
function parameter in case no matching parameter is available in the HTTP request
(see Example 9-10 ).
Example 9-10. Resource function extracting request parameters
xquery version "3.0";
module namespace ex = "http://example/restxq/7";
import module namespace rest = "http://exquery.org/ns/restxq";
declare
%rest:GET
%rest:path("/hello")
%rest:query-param("name", "{$name}", "stranger")
function ex:say-hello($name) {
<greeting>Hi there {$name}!</greeting>
};
We declare that we wish to only process paths that end with /hello relative to the
RESTXQ base URI.
We declare that we wish to extract the value of the name URI query parameter
and, if it is not available, to use the default value stranger . We declare that the
value should be injected into the function parameter $name .
This parameter will be set to the value of the URI query parameter declared by
%rest:path when invoked by RESTXQ.
The value of the URI query parameter will be output as part of the response.
By storing the XQuery anywhere in the database and granting it execute rights, you
may then access it by an HTTP GET to the URI http://localhost:8080/exist/restxq/hello .
For example, using cURL:
curl -v http://localhost:8080/exist/restxq/hello
Search WWH ::




Custom Search