RESTXQ and regexp
Friday, 22 February 2019 · 4 messages · last reply 4 Mar 2019
ML
Marco Lettere22 Feb 2019 12:05 #
Hello all,
according to the docs this should be possible:
(: Matches all paths with "app" as first, a number as second, and
"order" as third segment :)
declare %rest:path("app/{$code=[0-9]+}/order")
function page:order($full-path) { ... };
(: Matches all other all paths starting with "app/" :)
declare %rest:path("app/{$path=.+}")
function page:others($path) { ... };And it actually is... We are currently in the very unfortunate situation where we need the following:
(: Matches anything followed by /input :)
declare %rest:path("app/{$path=.+}/input")
function page:inputs($path) { ... };
(: Matches all other all paths starting with "app/" :)
declare %rest:path("app/{$path=.+}")
function page:others($path) { ... };Unfortunately this makes all the calls to be redirected to the page:others function ... is there a motivation behind it or could it be possible to work around that?
Thanks,
Marco.
LQ
Liam R. E. Quin24 Feb 2019 00:34 #
Quoted text · Marco Lettere · 8 lines
On Fri, 2019-02-22 at 12:05 +0100, Marco Lettere wrote: > (: Matches anything followed by /input :) > declare %rest:path("app/{$path=.+}/input") > function page:inputs($path) { ... }; > > (: Matches all other all paths starting with "app/" :) > declare %rest:path("app/{$path=.+}") > function page:others($path) { ... };
Can you use content negotiation/quality to say the /input one is preferred when both match? E.g. %rest:produces("*/*;qs=0.8") on the page:others function and */*;qs=1.0 on the input ont?
Liam
--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Web slave for vintage clipart http://www.fromoldbooks.org/
ML
Marco Lettere25 Feb 2019 13:11 #
Thanks for your suggestion Liam!
We've tried this out on the current deployment which involves version 8.6.3 and it didn't fix our specific use case.
My idea here (I'm not sure to make the correct assumption though) is that the proposition "if multiple candidate functions ar eleft over" stated in the docs is not holding here.
It rather looks as if BaseX is considering only the more generic one to match.
Regards,
Marco.
Quoted text · Marco Lettere · 17 lines
On 23/02/19 23:33, Liam R. E. Quin wrote: > On Fri, 2019-02-22 at 12:05 +0100, Marco Lettere wrote: > >> (: Matches anything followed by /input :) >> declare %rest:path("app/{$path=.+}/input") >> function page:inputs($path) { ... }; >> >> (: Matches all other all paths starting with "app/" :) >> declare %rest:path("app/{$path=.+}") >> function page:others($path) { ... }; > Can you use content negotiation/quality to say the /input one is > preferred when both match? E.g. %rest:produces("*/*;qs=0.8") on the > page:others function and */*;qs=1.0 on the input ont? > > Liam > >
CG
Hi Marco,
I can confirm that your RESTXQ paths were supposed to work as you expected them to work: If more than one endpoint is found in the first round, the one with a larger number of path segments should have been selected as favorite. In our implementation, the one with less segments was chosen, which is why your page:others function was evaluated in all cases.
I have corrected this behavior; the latest snapshot should work as expected. In addition, I have slightly revised our documentation.
Cheers
Christian
[1] https://github.com/BaseXdb/basex/commit/f421f06046fc4dddc25c6d82c3ee5a522b323568 [2] http://files.basex.org/releases/latest/
Quoted text · Marco Lettere · 34 lines
On Fri, Feb 22, 2019 at 12:05 PM Marco Lettere <m.lettere at gmail.com> wrote: > > Hello all, > > according to the docs this should be possible: > > (: Matches all paths with "app" as first, a number as second, and > "order" as third segment :) > declare %rest:path("app/{$code=[0-9]+}/order") > function page:order($full-path) { ... }; > > (: Matches all other all paths starting with "app/" :) > declare %rest:path("app/{$path=.+}") > function page:others($path) { ... }; > > And it actually is... We are currently in the very unfortunate situation > where we need the following: > > (: Matches anything followed by /input :) > declare %rest:path("app/{$path=.+}/input") > function page:inputs($path) { ... }; > > (: Matches all other all paths starting with "app/" :) > declare %rest:path("app/{$path=.+}") > function page:others($path) { ... }; > > Unfortunately this makes all the calls to be redirected to the > page:others function ... is there a motivation behind it or could it be > possible to work around that? > > Thanks, > > Marco. >
Written for BaseX 9.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery