Hm. I can’t reproduce it..
1. I stored your module as 'example.xqm' in the WEBPATH directory 2. I started basexhttp 3. I created an empty 'exampledb' database in the GUI and closed it again 4. I ran your script in the GUI (after rewriting fetch:xml(...) with <example/>) 5. I ran db:open('exambledb')
Did I do something wrong?
By the way, if possible, remove everything from your examples that required manual post-processing. Could you please check the following code and tell me how the returned XML looks like?
_ example.xqm ___________
module namespace example = 'http://localhost/example'; declare %rest:path("/example") %rest:POST("{$body}") function example:post($body) { $body };
_ test.xqm ___________
http:send-request( <http:request href="http://localhost:8984/example" method='POST'> <http:body media-type='text/xml'> <example/> </http:body> </http:request> )[2]
On my system, I get "<example/>".
On Thu, Sep 15, 2016 at 2:34 PM, chrisis chrisisanon@gmail.com wrote:
Hi Christian
Sorry, chopped that out of the real thing in a bit of a hurry and made a bit of a mess of it. Here's something slightly closer to a SSCE.
Module under WEBPATH
xquery version "3.1" encoding "utf-8"; module namespace example = 'http://localhost/example'; declare %rest:path("/example/post/{$fname}") %rest:POST("{$body}") %updating function example:post($fname, $body as document-node()) {db:replace('exampledb', '/post/'||$fname, $body) };
Script run in BaseX GUI
let $file := 'C:\temp\xq\example.xml' let $fname := 'example.xml' let $targetrestxqproc := 'http://localhost:8984/example/post/' let $body := fetch:xml($file, map { 'chop': true() }) return http:send-request(<http:request href="{$targetrestxqproc||$fname}" method='POST'> <http:body media-type='text/xml'>{$body}</http:body> </http:request>)
Result in exampledb is
<example xmlns:http="http://expath.org/ns/http-client"/>