http-postxqueryexist-dbexide

Exist DB XQuery: How to make an HTTP POST Request


Question: How do you make an HTTP POST request to an external service within Exist DB, ideally using just XQuery?

Motivation: I want to take a set of XML documents in Exist DB, and send each to an external server for processing, then I want to receive the result, and store them back in Exist DB.

I can accomplish this with an external script that interacts with the Exist DB REST interface, but I would like to it all within Exist DB and XQuery. Marklogic has a http request function that does POST requests under the xdmp namespace, which seems to accomplish this. Does something similar exist for Exist-DB?

Bonus points if the request body can be sent in JSON format.


Solution

  • eXist-db implements the EXPath HTTP Client specification, which defines a function, http:send-request, that can perform HTTP POST requests.

    For sample code, including sending a request body containing JSON, see eXist-db send JSON via POST request using eXPath Http_module.