[MarkLogic Dev General] DELETE method not allowed on HTTP Server?

Michael Blakeley michael.blakeley at marklogic.com
Thu Oct 30 08:52:23 PST 2008

Steve Mallen wrote:
> Given this restriction, I will probably end up using Apache Tomcat or 
> Jetty to intercept the requests, and make XDBC requests to Mark Logic 
> from there.  This will give me full URL mapping ability too.

I wanted to follow up on this thread, because the 4.0-1 release has 
changed the situation. Now it is possible to build REST-ful applications 
directly on a MarkLogic Server HTTPServer instance, including DELETE and 
PUT operations. Here's a quick example.

My HTTPServer is on port 8002, using application-level authentication, 
and I have set the error handler to "error-handler.xqy".

Test query:

<response xmlns="xdmp:http">
     <content-type>text/plain; charset=UTF-8</content-type>
DELETE /foo/bar/baz ok

The magic is in error-handler.xqy: it is written to treat any 404 error 
as a REST-ful request.

xquery version "1.0-ml";

declare variable $error:errors as element()? external;

declare variable $ERROR-404 := 404;

declare variable $CODE as item()+ := xdmp:get-response-code();

(: if the error was 'Not Found', handle it as a REST-ful request :)
if ($CODE[1] eq $ERROR-404) then (
   (: a real application would do something more interesting here  :)
   xdmp:set-response-code(200, 'OK'),
   text { xdmp:get-request-method(), xdmp:get-request-path(), 'ok' }
else <html>
     <title>Error: { $CODE }</title>
     <h1>Error: { $CODE }</h1>
       (: a real application might build a pretty error page here :)

Naturally this is just the skeleton of a real application, but I hope it 
conveys the general idea.

-- Mike

More information about the General mailing list