Adam Retter
adam@evolvedbinary.com
Declarative Amsterdam
@ CWI, Amsterdam
2025-11-06
@adamretter
Building a Web API
with an XML Database

About Me
-
Director of Evolved Binary
-
UK - Software, Consultancy, Training, and R&D
-
-
Co-founder and Co-owner of eXist Solutions
-
Germany - TEI Publisher software
-
-
Software Engineer / Prolific Open Source contributor
-
Elemental - Founder
-
eXist-db - 20 Years as Core contributor (last 9 as Main dev.)
-
RocksDB - 7 Years as RocksJava main developer
-
-
W3C XQuery Working Group - Invited expert
-
Founder of EXQuery, and creator of RESTXQ
-
Enjoys Research and Development, and Snowboarding

Web API with an XML Database
-
Web API
-
REST - Representational State Transfer
-
HATEOAS over HTTP
-
-
XML Database
"Steven Pemberton mentioned that he has coded a simple Web API for use with his XForms work.
I think it would be interesting to look at how Web APIs can be easily delivered on top of an XML database (i.e. Elemental) as they have many of the things you need already baked in.
We will look at RESTXQ and constructing an API in XQuery."
So... What do we need first?
Requirements!

Steven's Requirements
-
PUT an XML "instance" to the store
-
GET an XML instance from the store
-
"do a HEAD on it"
-
POST an element, that is appended to the end of an XML instance
Easy enough:
-
PUT an XML "instance" to the store
-
GET an XML instance from the store
Hmm, what is this:
-
"do a HEAD on it"
Resource Metadata:
-
HTTP HEAD Method
-
Retrieves only the HTTP Headers of a Resource. No content!
-
-
Often includes:
-
Content-Length -
Last-Modified -
ETag
-
-
Do we really need a dedicated HEAD method?
-
Might depend on the Client applications
-
Could just use conditional requests: e.g.
If-Modified-Since
-
Hmm... And what about this...:
-
POST an element, that is appended to the end of an XML instance
Aside - What is special about APIs for XForms?
-
Steven's application is written in XForms
-
XForms
-
Read/Update/Create Instances
-
An Instance is an XML Document
-
Most XForms implementations can HTTP GET/PUT/POST XML Documents
-
Do we really need update?
-
XForms can prepare an updated XML document client-side
-
XForms could just PUT the updated document over the top of an existing document
-
Approaches
-
Explicit Update
-
Create:
PUT /my-collection -
Retrieve:
GET /my-collection/my-document.xml -
Update:
POST /my-collection/my-document.xml
-
-
Just Create/Replace and Retrieve
-
Create:
PUT /my-collection -
Retrieve:
GET /my-collection/my-document.xml -
Replace:
PUT /my-collection/my-document.xml
-
-
How should Update work?
-
REST Semantics for Update are unclear
-
Should you use POST or PATCH?
Steven's Requirements (Refined)
-
Create a Document
-
HTTP PUT an XML document to the store
-
-
Retrieve a Document
-
HTTP GET an XML document from the store
-
Conditionally if modified
-
-
Update a Document
-
HTTP PATCH an XML document with modifications to the XML
-
Adam's Requirements Bonus Points:
-
List available Documents
-
HTTP GET a list of XML documents available from the store
-
-
Replace a Document
-
HTTP PUT an XML document to an existing URI
-
-
Delete a Document
-
HTTP DELETE an XML document from the store
-
-
JSON Support
-
Provide JSON versions of the API
-
Requirements ✅
...What should we do first?
Define our API!
Defining our REST API
-
Standard - Open API (3.2)
-
Swagger is a useful IDE for this
-
Our API specification: DASP XForms API - dasp-xforms-api/1.0.0
We will look at 3 different approaches:
-
Elemental's REST API
-
No Code
-
Served by Elemental's Web Server
Using an XML Database in your own Web API code
-
Bespoke Code
-
Any language - we will use Java 25
-
Use a language framework - we will use JAX-RS
-
Served by Micronaut/Jetty
Building a Web API directly in the XML Database
-
Bespoke Code
-
Implemented in XQuery
-
Use a language framework - we will use RESTXQ
-
Served by Elemental's Web Server
Elemental's REST API
Can Elemental's REST API meet our requirements?
-
Create a Document
-
HTTP PUT /exist/rest/db/dasp-documents/my-document.xml-
Request body is the content for the XML document
-
Need to know document ID in advance!
-
-
-
Retrieve a Document
-
HTTP GET /exist/rest/db/dasp-documents/my-document.xml-
Conditional: Supports
If-Modified-Sincerequest header
-
-
-
Update a Document
-
HTTP POST /exist/rest/db/dasp-documents/my-document.xml-
Request body is an XUpdate document
-
-
Can Elemental's REST API meet our requirements?
-
List available Documents
-
HTTP GET /exist/rest/db/dasp-documents
-
-
Replace a Document
-
HTTP PUT /exist/rest/db/dasp-documents/my-document.xml-
Request body is the new content for the XML document
-
-
-
Delete a Document
-
HTTP DELETE /exist/rest/db/dasp-documents/my-document.xml
-
-
JSON Support
-
Not without additional bespoke XQuery code!
-
Nice!
That was easy... Are we finished now?
-
✅ Delivered all 3 mandatory requirements
-
👍 Delivered 3 of 4 bouns requirements
-
But:
-
API is very generic
-
Using an XML Database in your own Web API code
Building a Web API directly in the XML Database
IN CONCLUSION
Conclusions
-
Just Elemental can be enough - No Code
-
Java implementation was easy, should be same for others (e.g. Python, PHP, etc)
-
RESTXQ implementation was simplest, least code
-
In future: Auto-generate RESTXQ code from Open API
Thanks
and
Questions
Building a Web API with an XML Database
By Adam Retter
Building a Web API with an XML Database
Declarative Amsterdam @ CWI, Amsterdam 2025-11-06
- 92