Sending DELETE request through HTTP Module

Monday, 2 July 2012 · 2 messages
SG
Seenivasan Gunabalan2 Jul 2012 15:16 #
hi, My objective is to delete the collections/files through the DELETE request using HTTP module. The DELETE operation does fine, when I ran it from BasexGUI. But if i put the same query inside delete.xq and invoke it by http://localhost:8984/rest?run=delete.xq, The request never returns any response and possibly got hanged. I need to restart the database to make the database to function. I am enclosing the xq i used, import module namespace http='http://expath.org/ns/http-client';
declare function local:cleanlist() {
         ('sample/record1','sample/record2','sample/record3')
};

declare function local:cleandb() {
     try {
         for $cl in local:cleanlist()
             return http:send-request(<http:request method="DELETE"
href="http://localhost:8984/rest/{$cl}"
                         status-only = "true"
                         username = "admin"
                         password = "admin"
send-authorization="true">
                      </http:request>)

     } catch err {
         err:description
     }
};

<cleandb>{ local:cleandb() }</cleandb>
CG
Christian Grün2 Jul 2012 16:13 #
Hi Seenivasan, updating REST requests should never be executed on the same machine, otherwise you will run into deadlocks or end up with corrupt data. Instead, you should use XQuery Update to directly delete the nodes or databases in question. This could e.g. look as follows:
  let $db := "sample"
  for $cl in ("record1", "record2", "record3")
  return db:delete($db, $path)
You'll find some more information on XQuery Update in our documentation. Hope this helps, Christian [1] http://docs.basex.org/wiki/XQuery_Update
Quoted text · Seenivasan Gunabalan · 37 lines
> My objective is to delete the collections/files through the DELETE > request using HTTP module. The DELETE operation does fine, when I ran it > from BasexGUI. But if i put the same query inside delete.xq and invoke it by > http://localhost:8984/rest?run=delete.xq, The request never returns any > response and possibly got hanged. I need to restart the database to make the > database to function. > > I am enclosing the xq i used, > > > import module namespace http='http://expath.org/ns/http-client'; > > declare function local:cleanlist() { > ('sample/record1','sample/record2','sample/record3') > }; > > declare function local:cleandb() { > try { > for $cl in local:cleanlist() > return http:send-request(<http:request method="DELETE" > href="http://localhost:8984/rest/{$cl}" > status-only = "true" > username = "admin" > password = "admin" > send-authorization="true"> > </http:request>) > > } catch err { > err:description > } > }; > > <cleandb>{ local:cleandb() }</cleandb> > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

⚡Generated with XQuery