1

The MarkLogic documentation gives information for a success response, but no information for a failed delete.

https://docs.marklogic.com/REST/DELETE/v1/documents

I would expect a 404 if the document doesn't exist, a 410 if it's already been deleted, or a 403 if I don't have authorization to delete the document.

From my limited testing, it seems I get a 204 if the document doesn't exist, and a 400 if I'm not authorized.

TravisChambers
  • 526
  • 4
  • 12

2 Answers2

1

Some REST practioners assert the DELETE request should be idempotent. So long as the document doesn't exist after the operation finishes, the operation succeeded.

That said, recent versions of the REST API allow a check parameter on document delete requests. If check is set to "exists," the operation should throw an error if the document doesn't exist.

In passing, I don't see how the 404 and 410 cases could be distinguished, given that there's no operational state on the server.

Hoping that helps,

ehennum
  • 7,295
  • 13
  • 9
  • Right. To get the 404 or 410 I would have to do some magic. Instead of deleting the item, I'd delete it's contents, but leave the resource at it's original URI, and do a read before a delete. Alternatively, and I think this is the solution I'll be opting for, I won't actually delete the document, but I'll instead add it to a special `deleted` collection that doesn't show up in search. – TravisChambers Mar 09 '19 at 02:13
0

You could take an API-first approach and build your own great REST APIs directly on MarkLogic where you take full control over the URI Path as well as response codes and anything else for that matter with XQRS.

declare
  %rest:DELETE
  %rest:path("/db/{$uri=.*}")
  %xdmp:update
function delete-doc($uri as xs:string) {
  if(fn:doc-available($uri)) then (
    xdmp:document-delete($uri),
    <rest:response>
      <http:response status="410" message="Gone"/>
    </rest:response>    
  )
  else (
    <rest:response>
      <http:response status="404" message="Not Found"/>
    </rest:response>
  )
};
Charles Foster
  • 338
  • 3
  • 5
  • i see what you're saying, but how can i return a 404 not found if i don't know the document wasn't found? i get a 204 success whether the document was found or not. i am building my own rest api on top of MarkLogic's and I'm trying to find out all the possible failed responses MarkLogic might send back, as well as how I can give users of my API accurate status codes. – TravisChambers Mar 07 '19 at 15:41
  • 1
    The approach I am suggesting involves building your own REST API which is directly served from MarkLogic Server itself using the XQRS framework over and above writing a Middle Tier component that interfaces with MarkLogic via MarkLogic's REST API. This approach would give you 100% control over MarkLogic as you're able to invoke any of MarkLogic's thousands of functions as well as having total control of what your REST APIs looks like. The XQRS framework allows you to build REST APIs in a manner that's similar to the very popular JAX-RS, whilst giving total freedom with the database. – Charles Foster Mar 07 '19 at 15:55
  • I'm with you now. I'll consider it, but rewriting the MarkLogic out of the box REST apis is not something I want to do. Especially in xquery. – TravisChambers Mar 07 '19 at 17:47