Database Reference
In-Depth Information
• The URL string becomes longer as the XQuery becomes longer, and URL encod‐
ing compounds this problem. Some HTTP clients and servers have limitations
on the length of the URLs they can handle!
A better approach than using HTTP GET queries for anything more than the simplest
XQueries is to use HTTP POST queries instead. The main advantage of HTTP GET
queries is that you can easily send them from any web browser's address bar, and this
advantage is negated as the queries get more complex. That said, there are plug-ins
for several browsers that enable you to send more complex requests, such as Postman
for Google Chrome and HttpRequester for Mozilla Firefox.
HTTP POST queries. When sending XQueries via HTTP POST to the REST Server API,
we need to place them in an XML document that contains the XQuery and any
parameters for the REST Server or XQuery itself. Let's look at how we would send
our simple query using HTTP POST :
<query xmlns= "http://exist.sourceforge.net/NS/exist" >
<text>
<![CDATA[
xquery version "1.0";
/person/name
]]>
</text>
</query>
We place the XQuery itself inside a CDATA section so as to avoid having to escape any
XML-sensitive characters in our XQuery. We can now POST the XML document con‐
taining the XQuery to the REST Server API using the following cURL command:
curl -X POST -H 'Content-Type: application/xml'
--data-binary @/tmp/person-name.xml
http://localhost:8080/exist/rest/db/people
The result of this query is exactly the same as that of the equivalent HTTP GET exam‐
ple earlier, but it is much easier to send larger queries using HTTP POST . Table 13-4
explains the cURL parameters used here.
Search WWH ::




Custom Search