On the documentation page on RESTXQ [1], the following example is given in the section headed 'Query parameters':
declare %rest:path("/params") %rest:query-param("id", "{$id}") %rest:query-param("add", "{$add}", 42, 43, 44) function page:params($value as xs:string?, $answer as xs:integer+) { <result id="{ $id }" sum="{ sum($add) }"/> };
Is it really the case that
%rest:query-param("id", "{$id}") %rest:query-param("add", "{$add}", 42, 43, 44)
will cause variables named $id and $add to be in scope in the function, even though there are no arguments with either of these two names? (And what values will $value and $answer have?)
Or is there a typo in the example?
If there is a typo in the example, it would be nice to fix it; if there is no typo in the example, it would be nice to explain to the user what is going on. I can't find any mention of rest:query-param in the draft RESTXQ spec [2], and where I do find mentions of rest:query-param, I have not yet found any explicit statement about what it does, in formal terms. I have been guessing, based on the other examples in [1] and on the statement there that "The following annotations can be used to bind request values to function arguments", that an annotation of the form
rest:query-param(X, "{$Y}", Z)
binds the value of the query parameter X in the URI to $Y, where $Y is the name of a parameter of the function being annotated.
I apologize for not simply tying the example to see if it works.
Michael
[1] http://docs.basex.org/wiki/RESTXQ [2] http://exquery.github.com/exquery/exquery-restxq-specification/restxq-1.0-sp...
Dear Michael,
you are correct and indeed this has been a mistake. The variable names given in the query parameters should match the ones given as function parameters. I just fixed this in our wiki, thanks for pointing it out. And I am quite surprised no one noticed this earlier, as this error seems to be around for a very long time.
I agree that there is no formal specification to be found about query-params(). However, your explanation is spot on.
Regards, Dirk
On 01/15/2015 03:50 AM, C. M. Sperberg-McQueen wrote:
On the documentation page on RESTXQ [1], the following example is given in the section headed 'Query parameters':
declare %rest:path("/params") %rest:query-param("id", "{$id}") %rest:query-param("add", "{$add}", 42, 43, 44) function page:params($value as xs:string?, $answer as xs:integer+) {
<result id="{ $id }" sum="{ sum($add) }"/> };
Is it really the case that
%rest:query-param("id", "{$id}") %rest:query-param("add", "{$add}", 42, 43, 44)
will cause variables named $id and $add to be in scope in the function, even though there are no arguments with either of these two names? (And what values will $value and $answer have?)
Or is there a typo in the example?
If there is a typo in the example, it would be nice to fix it; if there is no typo in the example, it would be nice to explain to the user what is going on. I can't find any mention of rest:query-param in the draft RESTXQ spec [2], and where I do find mentions of rest:query-param, I have not yet found any explicit statement about what it does, in formal terms. I have been guessing, based on the other examples in [1] and on the statement there that "The following annotations can be used to bind request values to function arguments", that an annotation of the form
rest:query-param(X, "{$Y}", Z)
binds the value of the query parameter X in the URI to $Y, where $Y is the name of a parameter of the function being annotated.
I apologize for not simply tying the example to see if it works.
Michael
[1] http://docs.basex.org/wiki/RESTXQ [2] http://exquery.github.com/exquery/exquery-restxq-specification/restxq-1.0-sp...
basex-talk@mailman.uni-konstanz.de