HTTP POST as xml

Monday, 6 May 2019 · 2 messages
RK
Robert Kirkpatrick6 May 2019 14:09 #

Hello,

I am trying to implement an XForm for posting data via:

<xf:submission resource="http://localhost:8984/test" method="post"
  serialization="application/xml" replace="all" />

It should invoke the following query (in webapp):

module namespace page = 'http://basex.org/examples/web-page';
declare
  %rest:path("/test")
  %rest:POST("{$data}")
function page:hello ( $data as element() )
as element() { $data };

But I get this instead: [image: image.png] TIA for any help, Robert.

MS
Michael Seiferle6 May 2019 16:21 #

Hi Robert,

Yeah, that’s not necessarily obvious, but the type of the document you post is „document-node()“ not element() — so simply change the function & argument types to document-node() and you will be fine.

Usually the the in-browser debugging > Network view helps with identifying such „low-level“ errors, yet I tend to use the command-line more often since I discovered httpie[1]

Quoted text · Robert Kirkpatrick · 4 lines
> echo "<xml/>"|http POST http://localhost:8984/test Content-Type:text/xml > HTTP/1.1 400 Bad Request > Stopped at /Users/michael/tmp/ml/webapp/foo.xqm, 5/10: > [XPTY0004] Cannot convert document-node() to element(): document-node {''}.

Hope this helps & best from Konstanz

Michael

[1] https://httpie.org

Quoted text · Robert Kirkpatrick · 22 lines
> Am 06.05.2019 um 14:09 schrieb Robert Kirkpatrick <robert at eridan.net>: > > Hello, > > I am trying to implement an XForm for posting data via: > > <xf:submission resource="http://localhost:8984/test <http://localhost:8984/test>" method="post" > serialization="application/xml" replace="all" /> > > It should invoke the following query (in webapp): > > module namespace page = 'http://basex.org/examples/web-page <http://basex.org/examples/web-page>'; > declare > %rest:path("/test") > %rest:POST("{$data}") > function page:hello ( $data as element() ) > as element() { $data }; > > But I get this instead: > <image.png> > TIA for any help, > Robert.

⚡Generated with XQuery