S. Sire
S. Sire

Reputation: 11

How to Call a Data Service using ExPath HTTP Client from third-part application?

Where to find documentation on how to call a Data Service deployed on Marklogic from an XQuery script using ExPath HTTP Client library ?

The only documentation I could find describes how to call it from a nodejs application (https://docs.marklogic.com/guide/node-dev/dataservicesnode) or from a Java application (https://docs.marklogic.com/guide/java/DataServices) using generated proxy classes.

I have a Data Service deployed on a Marklogic application server (Digest authentication). The service *.api file defines 1 parameter for this service :

"params": [
    {
      "name": "foobar",
      "datatype": "string",
      "desc": "blah blah"
    }
  ],

Now I want to call it from an xQuery script using EXPath HTTP Client library, running in eXist-DB. So I am using a call like : http:send-request($req, $uri, $bodies)

with $uri the address of the web service with $req an element such as

<http:request chunked="false" method="post" username="admin" password="PWD" auth-method="digest" send-authorization="true">
  <http:header name="Accept" value='application/xml'/>
  <http:multipart media-type="multipart/form-data" boundary="boundary">
    <http:header name="Content-Disposition" value='form-data; name="foobar"'/>
    <http:body media-type="application/json" method="text"/>
  </http:multipart>
</http:request>

with $bodies such as ("42") since I have in this example only 1 parameter

Unfortunately I always get this error from the Marklogic web service :

XDMP-ENDPOINTINVALIDPARAM: foobar has an invalid value per the endpoint declaration

Calling this web service with Postman with Digest Authentication and multipart/form-data Content-Type works fine, same as with curl (curl --DIGEST -u admin:PWD -v --location 'URI' --form 'foobar="42"').

Are there some specifies in the serialization of the request body for Marklogic Data Service that would make ExPath HTTP Client to fail ?

Are there other ways to serialize the data service parameters than multipart/form-data ?

LAST MINUTE

using another xquery HTTP Client library I could make it work... The difference is that ExPath HTTP Client library adds a Content-Type inside each part of the body and that seems to break Marklogic parser and cause the XDMP-ENDPOINTINVALIDPARAM error.

So this payload results in error :

--boundary
Content-Disposition: form-data; name="foobar"
Content-Type: application/json; charset=UTF-8

42
--boundary--

But this payload works :

--boundary
Content-Disposition: form-data; name="foobar"

42
--boundary--

If the first version is conformant with the multipart/form-data specification, then Marklogic request parser should support it, otherwise ExPath HTTP Client library should give a way to disable it.

Upvotes: 1

Views: 59

Answers (0)

Related Questions