Database Reference
In-Depth Information
curl -X POST -H
'Content-Type: application/xml'
--data-binary @/tmp/settlement-average-name.xml
http://localhost:8080/exist/rest/db/people
which could result in a response that starts with the element:
<exist:result
xmlns:exist=
"http://exist.sourceforge.net/NS/exist"
exist:hits=
"567"
exist:start=
"1"
exist:count=
"10"
exist:session=
"23"
>
We have omitted the entire response body for brevity, but the important thing to
note here is that the REST Server has executed our
POST
ed XQuery and found
567
results (
hits
attribute), and it is returning the first
10
results (indicated by the
start
and
count
attributes). In addition, the results have been cached and will be accessible
in the future using the session identifier
23
(
session
attribute).
So, we have returned our first page of
10
results, but how do we get our second page
of results? We send almost the same request as before, but this time on the
query
element we want to set the
session
attribute to the session identifier that we were
given by the response of the first request and increase the value of the
start
attribute,
so we end up with the following request:
<?xml version="1.0" encoding="UTF-8"?>
<query
xmlns=
"http://exist.sourceforge.net/NS/exist"
session=
"23"
cache=
"yes"
start=
"11"
max=
"10"
>
<text>
<![CDATA[
xquery version "1.0";
for $settlement in distinct-values(/person/residence/location/settlement)
let $average-age := avg(
/person[residence/location/settlement eq $settlement]/born/(year-from-date(
current-date()) - year-from-date(xs:date(./date))))
order by $average-age ascending
return
<settlement>
<name>{$settlement}</name>
<average-age>{$average-age}</average-age>
</settlement>
]]>
</text>
</query>
which we send to the REST Server by:
curl -X POST -H 'Content-Type: application/xml' --data-binary
@/tmp/settlement-average-name.page2.xml
http://localhost:8080/exist/rest/db/people
Search WWH ::
Custom Search