0

I have a RestXQ method:

declare
    %rest:path("/doSomething")
    %rest:POST
    %rest:form-param("name","{$name}")
    function page:doSomething($name as document-node())
    {
        (: Code... :)
    };

I tried to send a POST request to this method via XForms. As response on the client I get [XPTY0004] Cannot convert empty-sequence() to document-node(): (). I tried to remove document-node() but then the parameter $name is just empty.

The request parameter looks like this:

<data xmlns=""><name>Test</name></data>

Any solutions?

Ian Fako
  • 1,148
  • 1
  • 15
  • 34
  • 2
    Is your question why you get the error? That has to be because the body of your function must not be returning a document node. Or is your question why your function is not receiving the expected data for the “name” parameter? – Joe Wicentowski Aug 25 '18 at 16:12

1 Answers1

1

The problem is that %rest:form-param("name","{$name}") is for key-value pairs, but your method indicates that you want $name as document-node(). Those two things together don't make sense.

Instead of the form-param you likely want the body of the POST request, for that you would use the following:

declare
  %rest:path("/doSomething")
  %rest:POST("{$body}")
function page:doSomething($body as document-node())
{
    (: Code... :)
};

See http://www.adamretter.org.uk/papers/restful-xquery_january-2012.xhtml#media-example

adamretter
  • 3,885
  • 2
  • 23
  • 43