TravisChambers
TravisChambers

Reputation: 626

What does the MarkLogic out of the box rest api return when deleting a document fails?

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.

Upvotes: 1

Views: 150

Answers (2)

ehennum
ehennum

Reputation: 7335

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,

Upvotes: 1

Charles Foster
Charles Foster

Reputation: 338

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>
  )
};

Upvotes: 0

Related Questions