Question

I'm using a BaseX RESTXQ .xqm script to get an HTTP query parameter price from a URI, eg;

URI:    /foo/?price=20
Result: <price>20</price>

This is the .xqm code;

declare
  %rest:path("foo")
  %rest:query-param("price", "{$price}")
  function page:foo($price) {
    <price>{$price}</price>
  };

However, how can I get the whole query? Eg;

URI:     /foo/?hello=world&this=that&foo=bar
Result:  <query>hello=world&this=that&foo=bar</query>

My problem is that I don't know how many params the query will have or what those params might be called. There might be any number of params (zero to n) and they might be called anything at all. Being able to get the whole query as a single string would solve my problem.

Can this be done?

Was it helpful?

Solution

The current RESTXQ draft provides no solution for dynamically requesting query parameters.

In the related JAX-RS specification, several Context annotations exist to make additional request information available to a Java function (see an example). Newer versions of BaseX will provide a Request Module, which could be extended to provide dynamical access to all query parameters. You may want to write to the basex-talk mailing list or to Adam Retter (the inventor of RESTXQ) to further motivate such an extension.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top