REST Post XQuery

Saturday, 19 November 2011 · 3 messages · last reply 20 Nov 2011
LJ
Leigh L. Klotz, Jr.19 Nov 2011 01:33 #
I see that REST GET request supports the ?run=foo.xq style, which allows a GET to be handled by a pre-defined XQuery file. See http://docs.basex.org/wiki/REST#GET_Requests However, the REST POST (and other) requests do not support it. With support for XUpdate in BaseX, it is important to have the ability to POST (or PUT) application-defined data to a server-side XQuery, rather than having the client have to post the entire query. DELETE is useful as well, but takes on data. See http://docs.basex.org/wiki/REST#POST_Requests I took a quick look at RESTPost.java and RESTGet.java and see that it would be about 50 lines of work to make RESTPost support making the request entity available to the specified XQuery as context. Leigh.
CG
Christian Grün19 Nov 2011 22:02 #
Quoted text · Leigh L. Klotz, Jr. · 5 lines
> I see that REST GET request supports the ?run=foo.xq style, which allows a > GET to be handled by a pre-defined XQuery file. See > http://docs.basex.org/wiki/REST#GET_Requests > > However, the REST POST (and other) requests do not support it.
You may be gratified to hear that POST also supports the RUN operation. I've added a small example to the documentation: http://docs.basex.org/wiki/REST#POST_Requests
Quoted text · Leigh L. Klotz, Jr. · 3 lines
> With support for XUpdate in BaseX, it is important to have the ability to > POST (or PUT) application-defined data to a server-side XQuery, rather > than having the client have to post the entire query.
This is possible by adding a <rest:context/> element to your POST request. The element contents will then available as the context item of the server-side query; e.g.:
<rest:run xmlns:rest="http://www.basex.org/rest">
  <rest:text>query.xq</rest:text>
  <rest:context>
    <xml>
      <text>Hello</text>
      <text>World</text>
    </xml>
  </rest:context>
</rest:run>
Hope this helps, Christian
LJ
Leigh L Klotz, Jr.20 Nov 2011 00:22 #
Thanks, I did see those, but I would like to have the REST way, where the URI identifies the resource, which in this case is defined by an XQuery, and the request entity is the application data. So,
POST /rest/foo?run=abc.xql
<order>
  <topping>cheese</topping>
  <topping>pepperoni</topping>
</order>
So the RESTPost would support ?run. A better way might be to allow a separate mapping of resources to XQuery files, so maybe I will take a look at that. Leigh.
Quoted text · Christian Grün · 36 lines
On Nov 19, 2011 1:02 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: > > I see that REST GET request supports the ?run=foo.xq style, which allows > a > > GET to be handled by a pre-defined XQuery file. See > > http://docs.basex.org/wiki/REST#GET_Requests > > > > However, the REST POST (and other) requests do not support it. > > You may be gratified to hear that POST also supports the RUN > operation. I've added a small example to the documentation: > > http://docs.basex.org/wiki/REST#POST_Requests > > > With support for XUpdate in BaseX, it is important to have the ability to > > POST (or PUT) application-defined data to a server-side XQuery, rather > > than having the client have to post the entire query. > > This is possible by adding a <rest:context/> element to your POST > request. The element contents will then available as the context item > of the server-side query; e.g.: > > <rest:run xmlns:rest="http://www.basex.org/rest"> > <rest:text>query.xq</rest:text> > <rest:context> > <xml> > <text>Hello</text> > <text>World</text> > </xml> > </rest:context> > </rest:run> > > > Hope this helps, > Christian > >

⚡Generated with XQuery