Passing an array to REST HTTP service
Friday, 3 November 2023 · 4 messages
CF
Csaba Fekete3 Nov 2023 08:30 #
Hi
I'm wondering if this is at all possible...
I defined an array variable in my XQUERY:
declare variable $ca as array(xs:integer) external := [];How can I assign a value (e.g [1,2]) to this variable through the URL? I have already tried:
http://host:port/rest/dbname?run=query.xq&$ca[]=1&$ca[]=2
That didn't work. Neither did this:
http://host:port/rest/dbname?run=query.xq&$ca=1,2
Any hints are much appreciated.
Thanks
Csaba
MH
Martin Honnen3 Nov 2023 08:51 #
Quoted text · Csaba Fekete · 11 lines
On 03/11/2023 08:30, Csaba Fekete wrote: > > I defined an array variable in my XQUERY: > > declare variable $caas array(xs:integer)external := []; > > How can I assign a value (e.g [1,2]) to this variable through the URL? > I have already tried: > http://host:port/rest/dbname?run=query.xq&$ca[]=1&$ca[]=2 > That didn't work. Neither did this: > http://host:port/rest/dbname?run=query.xq&$ca=1,2
Perhaps
$ca=[1,2]? Not sure whether square brackets in a URL query part need some escaping, however.
CG
Hi Csaba,
The variable types of the REST API are limited to atomic values. With BaseX 11, however, it will be possible to bind multiple values [1]:
http://localhost:8080/rest?run=query&n=3&n=4&n=5
(: XQuery file: query.xq :)
declare variable $n as xs:integer* external;
array { $n }You can try the latest stable snapshot [2].
Best,
Christian
[1] https://docs.basex.org/wiki/REST#GET_Method_2
[2] https://files.basex.org/releases/latest/
Quoted text · Csaba Fekete · 19 lines
On Fri, Nov 3, 2023 at 8:30 AM Csaba Fekete <feketecsaba at gmail.com> wrote: > Hi > > I'm wondering if this is at all possible... > I defined an array variable in my XQUERY: > > declare variable $ca as array(xs:integer) external := []; > > > How can I assign a value (e.g [1,2]) to this variable through the URL? I > have already tried: > http://host:port/rest/dbname?run=query.xq&$ca[]=1&$ca[]=2 > That didn't work. Neither did this: > http://host:port/rest/dbname?run=query.xq&$ca=1,2 > > Any hints are much appreciated. > Thanks > Csaba >
CF
Csaba Fekete3 Nov 2023 16:17 #
Hi Christian
Thanks for your reply.
In the meantime I've found a workaround:
http://localhost:8080/rest?run=query&n=3,4,5
declare variable $n as xs:string external := "";
declare variable $n_arr as xs:integer* := tokenize($n, ",") ! xs:integer(.);Regards
Csaba
Quoted text · Christian Grün · 43 lines
On Fri, 3 Nov 2023 at 16:02, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Csaba, > > The variable types of the REST API are limited to atomic values. With > BaseX 11, however, it will be possible to bind multiple values [1]: > > http://localhost:8080/rest?run=query&n=3&n=4&n=5 > > (: XQuery file: query.xq :) > declare variable $n as xs:integer* external; > array { $n } > > You can try the latest stable snapshot [2]. > > Best, > Christian > > [1] https://docs.basex.org/wiki/REST#GET_Method_2 > [2] https://files.basex.org/releases/latest/ > > > On Fri, Nov 3, 2023 at 8:30 AM Csaba Fekete <feketecsaba at gmail.com> wrote: > >> Hi >> >> I'm wondering if this is at all possible... >> I defined an array variable in my XQUERY: >> >> declare variable $ca as array(xs:integer) external := []; >> >> >> How can I assign a value (e.g [1,2]) to this variable through the URL? I >> have already tried: >> http://host:port/rest/dbname?run=query.xq&$ca[]=1&$ca[]=2 >> That didn't work. Neither did this: >> http://host:port/rest/dbname?run=query.xq&$ca=1,2 >> >> Any hints are much appreciated. >> Thanks >> Csaba >> >
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery