Reputation: 815
In eXist 4.7, I have a simple API end point as an XQuery .xqm which receives a short XML document from a client (ie. an HTML form in a browser). I currently only send back a response of 200 or 400. For example, in simplified form:
if (request:get-method()="POST")
then
let $eval := validate:my-api-doc(request:get-data())
return
if ($eval/@status = "ok")
then response:set-status-code(200)
else response:set-status-code(400)
else response:set-status-code(405)
I now want to start sending XML (or possibly other content) back to the client. For example, if the user is creating a document with a mandatory "title" field and they submit it empty, I want to send back to the client the response:
<errors>
<error element="title">Mandatory field.</error>
</errors>
How do I get this XML content into the HTTP response? I cannot find a relevant eXist HTTP response
function in the documentation at https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/response .
Many thanks in advance.
Upvotes: 1
Views: 104
Reputation: 5294
To get XML content into your HTTP response, just return it inline as you would return XML content for any other query:
return
(
response:set-status-code(405),
<error>Oops!</error>
)
Upvotes: 2