can restxq add a document to the db and return an http response?
Hi, Is it possible with restxq to add a document to a db? And if so, to also return an http response? I am trying to get the first part working with something along these lines: declare %rest:path("form/") %rest:POST %rest:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) { let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root> return db:add("test_db", $new-doc, "test.xml") }; Many thanks, Colin
Hi Colin,
Is it possible with restxq to add a document to a db? And if so, to also return an http response?
sure; you need to mark your function as updating, and the db:output() function will allow you to return data. Your updated example is shown below. Hope this helps, Christian ___________________________________ module namespace page = 'http://basex.org/modules/web-page'; declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) { let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root> return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) };
That's great - thanks! I was looking here for list of all annotations: http://docs.basex.org/wiki/RESTXQ But now I see these - %public, %private, or %updating - on this page too: http://docs.basex.org/wiki/XQuery_3.0#Annotations Are there any other annotations recognized by basex? On Thu, Sep 6, 2012 at 3:37 PM, Christian Grün <christian.gruen@gmail.com>wrote:
Hi Colin,
Is it possible with restxq to add a document to a db? And if so, to also return an http response?
sure; you need to mark your function as updating, and the db:output() function will allow you to return data. Your updated example is shown below.
Hope this helps, Christian ___________________________________
module namespace page = 'http://basex.org/modules/web-page';
declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) {
let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root>
return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) };
Hi Christian, I am getting this error with the below code [FOUP0001] Document expected, <root>...</root> found. Is this a problem with the way $new-doc is declared? Thanks, Colin module namespace page = 'http://basex.org/modules/web-page'; declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) { let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root> return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) }; On Thu, Sep 6, 2012 at 3:44 PM, Colin McEnearney <colinmcenearney@gmail.com>wrote:
That's great - thanks!
I was looking here for list of all annotations:
http://docs.basex.org/wiki/RESTXQ
But now I see these - %public, %private, or %updating - on this page too:
http://docs.basex.org/wiki/XQuery_3.0#Annotations
Are there any other annotations recognized by basex?
On Thu, Sep 6, 2012 at 3:37 PM, Christian Grün <christian.gruen@gmail.com>wrote:
Hi Colin,
Is it possible with restxq to add a document to a db? And if so, to also return an http response?
sure; you need to mark your function as updating, and the db:output() function will allow you to return data. Your updated example is shown below.
Hope this helps, Christian ___________________________________
module namespace page = 'http://basex.org/modules/web-page';
declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) {
let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root>
return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) };
You need to additionally wrap your constructed element into a document node: let $new-doc:= document { <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root> } Hope this helps, Christian ___________________________
Hi Christian,
I am getting this error with the below code
[FOUP0001] Document expected, <root>...</root> found.
Is this a problem with the way $new-doc is declared?
Thanks, Colin
module namespace page = 'http://basex.org/modules/web-page';
declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) {
let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root>
return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) };
On Thu, Sep 6, 2012 at 3:44 PM, Colin McEnearney <colinmcenearney@gmail.com> wrote:
That's great - thanks!
I was looking here for list of all annotations:
http://docs.basex.org/wiki/RESTXQ
But now I see these - %public, %private, or %updating - on this page too:
http://docs.basex.org/wiki/XQuery_3.0#Annotations
Are there any other annotations recognized by basex?
On Thu, Sep 6, 2012 at 3:37 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Colin,
Is it possible with restxq to add a document to a db? And if so, to also return an http response?
sure; you need to mark your function as updating, and the db:output() function will allow you to return data. Your updated example is shown below.
Hope this helps, Christian ___________________________________
module namespace page = 'http://basex.org/modules/web-page';
declare %updating %restxq:path("form/") %restxq:POST %restxq:form-param("content","{$form-input}", "'no message delivered'") function page:add-doc($form-input as xs:string) {
let $new-doc:= <root> <tag> <form-data>{ $form-input }</form-data> </tag> </root>
return ( db:add("test_db", $new-doc, "test.xml"), db:output("database was updated.") ) };
participants (2)
-
Christian Grün -
Colin McEnearney