Database Reference
In-Depth Information
Table 13-4. cURL parameters for sample HTTP POST query
cURL parameters
Explanation
The
-X
parameter allows you to specify the HTTP request method.
In this example the method of the request is
POST
, as we want to
POST
the
XML document containing the XQuery to the REST Server.
-X
POST
eXist needs to know the Internet media type of the resource you are
POST
ing so
it can decide how to process it. The
-H
parameter allows you to specify an HTTP
request header, and we can inform eXist of the Internet media type by setting the
Content-Type
header.
In this example, because the XQuery is embedded in an XML document, we use
the Internet media type for an XML document.
-H 'Content-Type:
applica
tion/xml'
The
--data-binary
parameter allows you to send binary data in the
body
of
the request.
In this example we want to send an XML document; the
@
indicates that the data
should be read from the file
/tmp/person-name.xml
.
--data-binary
@/tmp/
person-name.xml
The final parameter is always the URI of the request.
In this instance, we are setting the context of the XQuery as the collection
/db/
people
.
http://localhost:8080/
exist/rest/db/people
Now, let's also look at how we would construct a version of our simple query where
the results are not wrapped by the REST Server using HTTP
POST
. To achieve this, we
simply add the same
wrap
parameter as before, but this time implemented as an
attribute to the
query
element:
<query
xmlns=
"http://exist.sourceforge.net/NS/exist"
wrap=
"no"
>
<text>
<![CDATA[
xquery version "1.0";
<names>{
/person/name
}</names>
]]>
</text>
</query>
REST Server parameters and paging results.
So far we have looked at just the
query
and
wrap
parameters available in the REST Server API for queries sent via either HTTP
GET
or HTTP
POST
. There are several other parameters available—which are all docu‐
Search WWH ::
Custom Search