2

I have a requirement to call the patch method from a custom REST endpoint.

I've searched in the MarkLogic documentation and found this sample code -

function get(context, params) {
  // return zero or more document nodes
};

function post(context, params, input) {
  // return zero or more document nodes
};

function put(context, params, input) {
  // return at most one document node
};

function deleteFunction(context, params) {
  // return at most one document node
};

exports.GET = get;
exports.POST = post;
exports.PUT = put;
exports.DELETE = deleteFunction; 

I currently use all of these JS extensions and they work just fine. I tried to make a patch function in the same fashion -

function patch(context, params, input) {
 return;
}

exports.PATCH = patch;

When I call the patch method through my endpoint, I get a "405 Method Not Allowed". Is patch in this manner not allowed in MarkLogic, is that why it is not included in the sample code?

Thanks in advance.

Hank
  • 131
  • 4

2 Answers2

2

MarkLogic's own REST extension mechanism stuff may not support PATCH methods, but XQRS certainly does.

Like so

declare
  %rest:PATCH
  %rest:path("/my/uri/how/i/want/it")
  %output:method("json")
function my-patch-request() {
  object-node {
    "my-key" : "my-value"
  }
};
Charles Foster
  • 338
  • 3
  • 5
0

The Resource Service Extension mechanism doesn't support a PATCH method.

The best verb to use for a patch service would likely be POST.

If the PATCH service is modifying documents, the implementation could use the xdmp.node(Insert*|Replace|Delete) functions such as

http://docs.marklogic.com/xdmp.nodeInsertBefore

One alternative is to stand up a separate appserver and either provide rules for PATCH in a declarative rewriter or use the xdmp.getRequestMethod() method in an imperative rewriter. See:

http://docs.marklogic.com/guide/app-dev/XMLrewriter

Hoping that helps,

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
ehennum
  • 7,295
  • 13
  • 9