Database Reference
In-Depth Information
return
if ( not ( empty ( $ image ))) then
$ image
else
<rest:response>
<http:response status = "{ $ ii:HTTP-NOT-FOUND }" >
<http:header name = " Content-Type " value = " application/xml " />
< / http:response >
< / rest:response>
} ;
We declare that we are only interested in processing HTTP GET requests.
We declare that we are only interested in processing HTTP requests that have a
URI (relative to the RESTXQ API) starting with /image and followed by any path
segment , which should be extracted into the function parameter $image-name .
We declare that we are only interested in consuming HTTP requests that can
accept a response with Content-Type image/jpeg .
We declare that we would like any body returned by our resource function to be
serialized to the HTTP response as binary.
The $image-name will receive the value of a path segment from the URI when the
function is executed, as we declared in ??? .
We call the function ii:get-image with the identifier of the image ( $image-
name ). This function has been omitted for brevity, but all you need to know right
now is that it retrieves an image previously stored into the database; otherwise
(i.e., if there is no image with that identifier in the database), it returns an empty
sequence.
We have an image, so we return it from the resource function to be serialized to
the HTTP response.
Alternatively, if there was no image in the database matching the identifier, we
set the response status to 404 Not Found .
Retrieve a thumbnail representation of an image from the database
The API provided by the image-api.xqm file allows you to send an HTTP GET to it via
the RESTXQ API to get a thumbnail of a previously stored image. If the URI in your
HTTP request includes an identifier of an image previously stored by the API pre‐
fixed by thumbnail/ , it will return a thumbnail representation of that image. The
image-api.xqm file will generate the thumbnail on the fly, store it into the database,
Search WWH ::




Custom Search