Database Reference
In-Depth Information
declare
%rest:POST("{$body}")
function ex:echo($body) {
<received>{$body}</received>
};
We declare that we wish to process only HTTP POST requests, and that any
request body should be extracted and injected into the function parameter
named $body .
This parameter will be set to the value of the request body declared when
invoked by RESTXQ.
The request body 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 requesting by HTTP POST any URI under http://localhost:8080/
exist/restxq . For example, given the following simple XML file:
<test> 123 </test>
using cURL to POST the XML file:
$ curl -X POST -H 'Content-Type: application/xml' -d @/tmp/test.xml
http://localhost:8080/exist/restxq/something
results in:
<received>
< test >123</test>
</received>
Note that the content of test.xml has been received by the server and placed
inside the received element for the response by our XQuery function.
When extracting the HTTP request body for a POST or PUT ,
RESTXQ will attempt to automatically process the request body
and provide the correct data type for you. The process for automatā€
ically converting the request body is as follows:
1. Is there an HTTP Content-Type header indicating that the
content is of a binary type (looked up in $EXIST_HOME/
mime-types.xml )? If so, return an xs:base64Binary value of
the request body.
2. Try to parse the request body as XML; is it XML? If so, return
it as a document-node() value.
3. Return the body as an xs:string .
Search WWH ::




Custom Search