Database Reference
In-Depth Information
POST Requests
HTTP
POST
requests can be used for three distinct purposes:
• If the remainder of the URI (the part after
/exist/rest
) references an XQuery pro‐
gram stored in the database, it will be executed.
• If the body of the
POST
request is a valid XUpdate document, the XUpdate pro‐
cessor will be invoked to update the database. An explanation of how this works
and the XUpdate XML format is described in
“XUpdate” on page 105
.
• If the body of the
POST
request is XML and uses the
http://exist.source
forge.net/NS/exist
namespace, it is interpreted as a so-called
extended query
request
. These can be used to post complex XQuery scripts that are too large or
too unwieldy to pass in a
_query
parameter of a
GET
request. The result will be
wrapped in an
exist:result
element. The XML format for extended query
requests is described in
“Extended query request XML format” on page 99
.
For example, let's fire an HTTP
POST
request containing an extended query request at
our own database using the eXist
httpclient
extension module:
let
$
URI
:=
'http://localhost:8080/exist/rest/doesnotmatter'
let
$
query
:=
'for $i in 1 to 10 return <Result index="{$i}"/>'
let
$
request
:=
<query
xmlns
=
"
http://exist.sourceforge.net/NS/exist
"
start
=
"
3
"
max
=
"
3
"
>
<text>
{
$
query
}
</text>
</query>
return
httpclient:post
(
xs:anyURI
(
$
URI
),
$
request
,
false
(),
())
The result will be something like:
<httpclient:response
xmlns:httpclient=
"http://exist-db.org/xquery/httpclient"
statusCode=
"200"
>
<httpclient:headers>
<httpclient:header
name=
"Date"
value=
"Mon, 17 Sep 2012 12:45:02 GMT"
/>
<httpclient:header
name=
"Set-Cookie"
value=
"JSESSIONID=4mpvajj2ez99sa2ik31kzjvq;Path=/exist"
/>
<httpclient:header
name=
"Expires"
value=
"Thu, 01 Jan 1970 00:00:00 GMT"
/>
<httpclient:header
name=
"Content-Type"
value=
"application/xml;
charset=UTF-8"
/>
<httpclient:header
name=
"Transfer-Encoding"
value=
"chunked"
/>
<httpclient:header
name=
"Server"
value=
"Jetty(7.5.4.v20111024)"
/>
</httpclient:headers>
<httpclient:body
mimetype=
"application/xml; charset=UTF-8"
type=
"xml"
>
<exist:result
xmlns:exist=
"http://exist.sourceforge.net/NS/exist"
exist:hits=
"10"
exist:start=
"3"
exist:count=
"3"
>
<Result
index=
"3"
/>
<Result
index=
"4"
/>
<Result
index=
"5"
/>
Search WWH ::
Custom Search