RESTXQ example of query parameters
Thursday, 15 January 2015 · 2 messages
CS
C. M. Sperberg-McQueen15 Jan 2015 04:50 #
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-specification.html
--
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com
* http://cmsmcq.com/mib
* http://balisage.net
****************************************************************
DK
Dirk Kirsten15 Jan 2015 09:13 #
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
Quoted text · C. M. Sperberg-McQueen · 49 lines
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-specification.html >
--
Dirk Kirsten, BaseX GmbH, http://basexgmbh.de
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery