A question about RESTXQ rest:form-param()

Wednesday, 22 April 2020 · 8 messages · last reply 23 Apr 2020
ZD
Zimmel, Daniel22 Apr 2020 11:26 #
Hi, in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? Best, Daniel
ZD
Zimmel, Daniel22 Apr 2020 12:18 #
Hi Daniel, RTFM. Simply pass the body in %rest:POST("{$body}"). Sorry for disturbing! Daniel
Quoted text · Zimmel, Daniel · 8 lines
-----Ursprüngliche Nachricht----- Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> Gesendet: Mittwoch, 22. April 2020 11:27 An: BaseX <basex-talk at mailman.uni-konstanz.de> Betreff: [basex-talk] A question about RESTXQ rest:form-param() Hi, in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? Best, Daniel
ML
Marco Lettere22 Apr 2020 14:24 #
Hi Daniel, another way is to use request:* functions [1] available for programmatic inspection of the request. Cheers, M. [1] https://docs.basex.org/wiki/Request_Module
Quoted text · Daniel · 21 lines
On 22/04/20 12:18, Zimmel, Daniel wrote: > Hi Daniel, > > RTFM. Simply pass the body in %rest:POST("{$body}"). > > Sorry for disturbing! > > Daniel > > -----Ursprüngliche Nachricht----- > Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> > Gesendet: Mittwoch, 22. April 2020 11:27 > An: BaseX <basex-talk at mailman.uni-konstanz.de> > Betreff: [basex-talk] A question about RESTXQ rest:form-param() > > Hi, > > in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? > > Best, Daniel >
ZD
Zimmel, Daniel22 Apr 2020 15:22 #
Thanks for the hint Marco, I just tried request:parameter-names(): that one works with GET but with POST I get an empty-sequence, I am not sure what the problem is here. I can access the full (unparsed) body, though (I can use that). Daniel
Quoted text · Marco Lettere · 31 lines
-----Ursprüngliche Nachricht----- Von: Marco Lettere <m.lettere at gmail.com> Gesendet: Mittwoch, 22. April 2020 14:24 An: basex-talk at mailman.uni-konstanz.de Betreff: Re: [basex-talk] A question about RESTXQ rest:form-param() Hi Daniel, another way is to use request:* functions [1] available for programmatic inspection of the request. Cheers, M. [1] https://docs.basex.org/wiki/Request_Module On 22/04/20 12:18, Zimmel, Daniel wrote: > Hi Daniel, > > RTFM. Simply pass the body in %rest:POST("{$body}"). > > Sorry for disturbing! > > Daniel > > -----Ursprüngliche Nachricht----- > Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> > Gesendet: Mittwoch, 22. April 2020 11:27 > An: BaseX <basex-talk at mailman.uni-konstanz.de> > Betreff: [basex-talk] A question about RESTXQ rest:form-param() > > Hi, > > in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? > > Best, Daniel >
ML
Marco Lettere22 Apr 2020 15:31 #
Are you setting the mime type to "application/x-www-form-urlencoded"? This is the prerequisite in order to get the body of a post parsed to form parameters. M.
Quoted text · Daniel · 43 lines
On 22/04/20 15:22, Zimmel, Daniel wrote: > Thanks for the hint Marco, > > I just tried request:parameter-names(): that one works with GET but with POST I get an empty-sequence, I am not sure what the problem is here. > I can access the full (unparsed) body, though (I can use that). > > Daniel > > -----Ursprüngliche Nachricht----- > Von: Marco Lettere <m.lettere at gmail.com> > Gesendet: Mittwoch, 22. April 2020 14:24 > An: basex-talk at mailman.uni-konstanz.de > Betreff: Re: [basex-talk] A question about RESTXQ rest:form-param() > > Hi Daniel, > another way is to use request:* functions [1] available for programmatic inspection of the request. > Cheers, > M. > > [1] https://docs.basex.org/wiki/Request_Module > > > On 22/04/20 12:18, Zimmel, Daniel wrote: >> Hi Daniel, >> >> RTFM. Simply pass the body in %rest:POST("{$body}"). >> >> Sorry for disturbing! >> >> Daniel >> >> -----Ursprüngliche Nachricht----- >> Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> >> Gesendet: Mittwoch, 22. April 2020 11:27 >> An: BaseX <basex-talk at mailman.uni-konstanz.de> >> Betreff: [basex-talk] A question about RESTXQ rest:form-param() >> >> Hi, >> >> in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? >> >> Best, Daniel >>
ZD
Zimmel, Daniel22 Apr 2020 16:03 #
the mime type seems correct, all params are being sent. I do not have problems getting the body, only request:parameter-names() does not give any values. (request:header works, for example)
Quoted text · Marco Lettere · 51 lines
-----Ursprüngliche Nachricht----- Von: Marco Lettere <m.lettere at gmail.com> Gesendet: Mittwoch, 22. April 2020 15:31 An: Zimmel, Daniel <D.Zimmel at ESVmedien.de>; basex-talk at mailman.uni-konstanz.de Betreff: Re: AW: [basex-talk] A question about RESTXQ rest:form-param() Are you setting the mime type to "application/x-www-form-urlencoded"? This is the prerequisite in order to get the body of a post parsed to form parameters. M. On 22/04/20 15:22, Zimmel, Daniel wrote: > Thanks for the hint Marco, > > I just tried request:parameter-names(): that one works with GET but with POST I get an empty-sequence, I am not sure what the problem is here. > I can access the full (unparsed) body, though (I can use that). > > Daniel > > -----Ursprüngliche Nachricht----- > Von: Marco Lettere <m.lettere at gmail.com> > Gesendet: Mittwoch, 22. April 2020 14:24 > An: basex-talk at mailman.uni-konstanz.de > Betreff: Re: [basex-talk] A question about RESTXQ rest:form-param() > > Hi Daniel, > another way is to use request:* functions [1] available for programmatic inspection of the request. > Cheers, > M. > > [1] https://docs.basex.org/wiki/Request_Module > > > On 22/04/20 12:18, Zimmel, Daniel wrote: >> Hi Daniel, >> >> RTFM. Simply pass the body in %rest:POST("{$body}"). >> >> Sorry for disturbing! >> >> Daniel >> >> -----Ursprüngliche Nachricht----- >> Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> >> Gesendet: Mittwoch, 22. April 2020 11:27 >> An: BaseX <basex-talk at mailman.uni-konstanz.de> >> Betreff: [basex-talk] A question about RESTXQ rest:form-param() >> >> Hi, >> >> in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? >> >> Best, Daniel >>
ML
Marco Lettere23 Apr 2020 10:39 #
I set up this restxq [1]. And call it with something like [2]. Got an output of [3] which looks like what I expect. M. [1] module namespace t = "urn:test";
declare
   %rest:path("test")
   %rest:POST
   %rest:consumes("application/x-www-form-urlencoded")
   %output:method("html")
function t:test() {
  <html>
    <body>
      <p>{request:parameter-names() ! (. || "=" ||
request:parameter(.))}</p>
    </body>
  </html>
};
[2] curl --location --request POST 'http://localhost:8984/test' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'param1=Hello' \ --data-urlencode 'param2=World'
[3]
<html>
<body>
<p>param1=Hello param2=World</p>
</body>
</html>
Quoted text · Daniel · 56 lines
On 22/04/20 16:03, Zimmel, Daniel wrote: > the mime type seems correct, all params are being sent. I do not have problems getting the body, only request:parameter-names() does not give any values. (request:header works, for example) > > -----Ursprüngliche Nachricht----- > Von: Marco Lettere <m.lettere at gmail.com> > Gesendet: Mittwoch, 22. April 2020 15:31 > An: Zimmel, Daniel <D.Zimmel at ESVmedien.de>; basex-talk at mailman.uni-konstanz.de > Betreff: Re: AW: [basex-talk] A question about RESTXQ rest:form-param() > > Are you setting the mime type to "application/x-www-form-urlencoded"? > This is the prerequisite in order to get the body of a post parsed to form parameters. > M. > > On 22/04/20 15:22, Zimmel, Daniel wrote: >> Thanks for the hint Marco, >> >> I just tried request:parameter-names(): that one works with GET but with POST I get an empty-sequence, I am not sure what the problem is here. >> I can access the full (unparsed) body, though (I can use that). >> >> Daniel >> >> -----Ursprüngliche Nachricht----- >> Von: Marco Lettere <m.lettere at gmail.com> >> Gesendet: Mittwoch, 22. April 2020 14:24 >> An: basex-talk at mailman.uni-konstanz.de >> Betreff: Re: [basex-talk] A question about RESTXQ rest:form-param() >> >> Hi Daniel, >> another way is to use request:* functions [1] available for programmatic inspection of the request. >> Cheers, >> M. >> >> [1] https://docs.basex.org/wiki/Request_Module >> >> >> On 22/04/20 12:18, Zimmel, Daniel wrote: >>> Hi Daniel, >>> >>> RTFM. Simply pass the body in %rest:POST("{$body}"). >>> >>> Sorry for disturbing! >>> >>> Daniel >>> >>> -----Ursprüngliche Nachricht----- >>> Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de> >>> Gesendet: Mittwoch, 22. April 2020 11:27 >>> An: BaseX <basex-talk at mailman.uni-konstanz.de> >>> Betreff: [basex-talk] A question about RESTXQ rest:form-param() >>> >>> Hi, >>> >>> in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? >>> >>> Best, Daniel >>>
ZD
Zimmel, Daniel23 Apr 2020 12:34 #
hmm, what is wrong with this stripped example? ######## form.xqm: module namespace page = 'http://basex.org/examples/web-page'; declare %rest:path("/esv/fun/form") %rest:single
function page:form() {

  let $body :=
  <div>
    <form action="/esv/test-form" id="myform2" method="post">
      <input type="text" name="foo"></input>
      <input type="hidden" name="key" value="key"/>
      <input type="submit" value="submit"></input>
    </form>
 </div>
  return (web:response-header(map {'method':'xhtml'}),
          $body)
};
######## test-form.xqm: module namespace esv = 'esv/queries'; declare %rest:POST("{$body}") %rest:form-param("key", "{$key}") %rest:path("/esv/test-form") %rest:consumes("application/x-www-form-urlencoded") %rest:single %output:method("text") function esv:test-form( $body as xs:string, $key as xs:string ) { "parameter-names(): " || request:parameter-names(), "$body: " || $body, "$key: " || $key }; ######## output: parameter-names(): $body: foo=bar&key=key $key: key
Quoted text · Marco Lettere · 71 lines
Von: Marco Lettere <m.lettere at gmail.com> Gesendet: Donnerstag, 23. April 2020 10:40 An: Zimmel, Daniel <D.Zimmel at ESVmedien.de>; basex-talk at mailman.uni-konstanz.de Betreff: Re: AW: AW: [basex-talk] A question about RESTXQ rest:form-param() I set up this restxq [1]. And call it with something like [2]. Got an output of [3] which looks like what I expect. M. [1] module namespace t = "urn:test"; declare %rest:path("test") %rest:POST %rest:consumes("application/x-www-form-urlencoded") %output:method("html") function t:test() { <html> <body> <p>{request:parameter-names() ! (. || "=" || request:parameter(.))}</p> </body> </html> }; [2] curl --location --request POST 'http://localhost:8984/test' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'param1=Hello' \ --data-urlencode 'param2=World' [3] <html> <body> <p>param1=Hello param2=World</p> </body> </html> On 22/04/20 16:03, Zimmel, Daniel wrote: the mime type seems correct, all params are being sent. I do not have problems getting the body, only request:parameter-names() does not give any values. (request:header works, for example) -----Ursprüngliche Nachricht----- Von: Marco Lettere <m.lettere at gmail.com><mailto:m.lettere at gmail.com> Gesendet: Mittwoch, 22. April 2020 15:31 An: Zimmel, Daniel <D.Zimmel at ESVmedien.de><mailto:D.Zimmel at ESVmedien.de>; basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Betreff: Re: AW: [basex-talk] A question about RESTXQ rest:form-param() Are you setting the mime type to "application/x-www-form-urlencoded"? This is the prerequisite in order to get the body of a post parsed to form parameters. M. On 22/04/20 15:22, Zimmel, Daniel wrote: Thanks for the hint Marco, I just tried request:parameter-names(): that one works with GET but with POST I get an empty-sequence, I am not sure what the problem is here. I can access the full (unparsed) body, though (I can use that). Daniel -----Ursprüngliche Nachricht----- Von: Marco Lettere <m.lettere at gmail.com><mailto:m.lettere at gmail.com> Gesendet: Mittwoch, 22. April 2020 14:24 An: basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Betreff: Re: [basex-talk] A question about RESTXQ rest:form-param() Hi Daniel, another way is to use request:* functions [1] available for programmatic inspection of the request. Cheers, M. [1] https://docs.basex.org/wiki/Request_Module On 22/04/20 12:18, Zimmel, Daniel wrote: Hi Daniel, RTFM. Simply pass the body in %rest:POST("{$body}"). Sorry for disturbing! Daniel -----Ursprüngliche Nachricht----- Von: Zimmel, Daniel <D.Zimmel at ESVmedien.de><mailto:D.Zimmel at ESVmedien.de> Gesendet: Mittwoch, 22. April 2020 11:27 An: BaseX <basex-talk at mailman.uni-konstanz.de><mailto:basex-talk at mailman.uni-konstanz.de> Betreff: [basex-talk] A question about RESTXQ rest:form-param() Hi, in an HTML form with a RESTXQ POST action, do I really have to declare %rest:form-param() for every param, or is there a way to pass the full query component in one parameter? Best, Daniel

⚡Generated with XQuery