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:

xdmp:http-delete('http://localhost:8002/foo/bar/baz')
=>
<response xmlns="xdmp:http">
  <code>200</code>
  <message>OK</message>
  <headers>
    <server>MarkLogic</server>
    <content-type>text/plain; charset=UTF-8</content-type>
    <content-length>22</content-length>
    <connection>close</connection>
  </headers>
</response>
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>
  <head>
    <title>Error: { $CODE }</title>
  </head>
  <body>
    <h1>Error: { $CODE }</h1>
    {
      (: a real application might build a pretty error page here :)
      $error:errors
    }
  </body>
</html>

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

-- Mike
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to