Database Reference
In-Depth Information
Constraint annotations
Constraint annotations identify and limit the scope of HTTP requests that may
be processed by a resource function. Constraint annotations allow you to specify,
for example, the URI, HTTP method, and Internet media types that your func‐
tion is interested in processing.
Parameter annotations
Parameter annotations extract properties of an HTTP request (matching the
constraint annotations) and inject the values as parameters to your resource
function. Parameter annotations allow you to extract parameters from the URI
query, HTTP header, HTTP cookie, and POST ed HTML forms.
HTTP method constraint annotations
A resource function may have one or more method constraint annotations . A method
constraint annotation constrains the HTTP methods that a resource function may
process. RESTXQ currently supports the HTTP methods GET , HEAD , POST , PUT , and
DELETE . See Example 9-4 .
Example 9-4. Simple resource function that services all incoming GET requests
xquery version "3.0";
module namespace ex = "http://example/restxq/1";
import module namespace rest = "http://exquery.org/ns/restxq";
declare
%rest:GET
function ex:not-found() {
<result>The requested page could not be found!</result>
};
A RESTXQ resource constraint annotation for the HTTP method GET .
The XQuery in Example 9-4 is perhaps the simplest example of using RESTXQ; it will
simply return a response for any HTTP GET request to eXist's RESTXQ Server.
By storing the XQuery anywhere in the database and granting it execute rights, you
may then access it by requesting by HTTP GET any URI under http://localhost:8080/
exist/restxq . For example, using cURL:
$ curl -v http://localhost:8080/exist/restxq/any/thing/at/all
results in:
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Adding handle: conn: 0x7f8091007200
Search WWH ::




Custom Search