Database Reference
In-Depth Information
For further information about XUpdate, see the XUpdate 1.0 Specification and
“XUpdate” on page 105 .
XUpdate is just one mechanism for updating documents in eXist.
As an alternative, you can make use of the XQuery update exten‐
sion in your XQueries (see “eXist's XQuery Update Extension” on
page 102 ), which of course may be sent to the REST Server or
invoked by the REST Server as stored queries, as described next.
Executing stored queries
Perhaps the most interesting and flexible feature of the REST Server API is that it
allows you to invoke stored XQuery and XProc by making HTTP requests. This
means that you can potentially write complex XQueries split across several main and
library modules, store them into the database, and have them react to requests made
to the REST Server API. This facility, coupled with eXist's extensions for XQuery,
enables you to easily build your own HTTP/REST APIs in XQuery, or even entire
web applications.
When working with stored queries and the REST Server API, it is very likely that you
will want to use at least the request and response XQuery extension modules in
your XQueries to work with the HTTP request and response. You can find more
details on these in “The request Extension Module” on page 209 and “The response
Extension Module” on page 211 , respectively. Building web applications using this
approach (among others) is discussed in Chapter 9 , but for the purposes of integra‐
tion we will demonstrate a simple example here.
Supplied alongside this chapter is the XQuery file chapters/integration/rest-stored-
query/image-api.xq in the book-code Git repository (see “Getting the Source Code” on
page 15 ) that, when stored into the database and subsequently called via the REST
Server API, will deliver a simple custom REST API for manipulating images. To use
the XQuery as well as store it into the database (for example, in the /db collection),
you also need to ensure: 1) that the image-api.xq file has execute access within the
database by the calling user so that it may be executed; 2) that the collection /db/
images exists and is writable by the calling user; and 3) that the image XQuery exten‐
sion module is enabled in $EXIST_HOME/conf.xml . The custom REST API provides
the following three image manipulation functions:
• Store a JPEG image received over HTTP into the database.
• Retrieve a stored image from the database.
• Retrieve a thumbnail representation of an image from the database.
Let's now look at the XQuery code in detail, and how it performs each of these
functions.
Search WWH ::




Custom Search