0
votes

I am using inbuilt rest end point in Marklogic that allow me to call modules in stored in module database in Marklogic.

http://localhost:8000/LATEST/invoke?data-urlencode=module=/modules/module.xqy&database=databasename&data-urlencode=vars='{"word1":"hello","word2":"world"}'

Does it also provide any option to call direct function present within lib module?

Using vars option it allows us to pass external parameter to the invoking modules. It seems that vars option only allow to pass primitive values to external parameter to invoking module.

But how we can use this vars option to pass XML data to invoking module so that it can be access through external variable defined within module.

Any suggestion would be appreciated.

Note : I am using postman for testing of rest API.

Many thanks.

1
The suggestion below to use a REST extension is spot on, but I wanted to add that you are not limited to primitive data types for external variable values passed to invoke. For example, assuming the external var in your module is declared to have element() type, you could just pass in a serialized XML element for the value: {"myvar":"<foo>bar</foo>"} and handle it as such in the invoked module. - kcoleman

1 Answers

4
votes

Since your goal is to get to a library function, consider creating a REST extension instead of using /invoke with a main module. A REST extension can implement your choice of HTTP verbs and accept input in whatever for you'd like. The extension can then convert those inputs to function parameters and call the function.

For more information about REST extensions, see Extending the REST API, which includes an example XQuery extension.