Reputation: 15092
I have a custom REST endpoint written in JavaScript. In JavaScript extensions, POST actions run in query mode, so they cannot update data, so I need to start a new transaction with xdmp.eval, which means I need execute permission on xdmp.eval
. How can I apply an amp to the JavaScript extension?
I'm deploying the endpoint via DHF 5, so it's located in src/main/ml-modules/services/my-endpoint.sjs
. After deployment, in the modules database, /marklogic.rest.resource/my-endpoint/assets/resource.sjs
as been created, but also resource.xqy
and metadata.xml
. I actually tried creating three amps, one for each of those documents, but it doesn't seem to grant the necessary xdmp.eval
permission. I keep getting an error message:
SEC-PRIV: xdmp.eval(...) -- Need privilege: http://marklogic.com/xdmp/privileges/xdmp-eval
As a workaround, I think I can write a wrapper around the call to xdmp.eval
and create an amp on that. I'd just like to know if it's possible to amp the endpoint directly.
Upvotes: 1
Views: 68
Reputation: 15092
I think I've found how to do this correctly.
post
method in the document, that is, the local name in the amp needs to be "post"./marklogic.rest.resource/my-endpoint/assets/resource.xqy
. The sjs and metadata documents can be ignored.http://marklogic.com/rest-api/resource/my-endpoint
.I guess behind the scenes MarkLogic executes the endpoint via the XQuery wrapper and the JavaScript module is invoked in a way that an amp on the .sjs document is not applied to it.
Upvotes: 2