Hi Luke, That’s a classical recommendation for RESTXQ, which gives you a more powerful and flexible framework for writing custom REST APIs. Did you already have a look at it?
Best, Christian On Wed, Jan 22, 2020 at 2:33 AM ERRINGTON Luke <luke.erring...@sydac.com> wrote: > > Hi Christian, > > Thanks for that. That's exactly what I was hoping for (and I thought I tried > that, but must have done something wrong). > > Now for the trickier part of the problem: > > Let's say that I want to add a file to the database, but I want to do it > through a server-side XQuery, so that it can validate, etc. Can I do this > using the context of the call, or do I have to pass the name of the database > as an argument? > > e.g. > > db:add("Test", <a/>, "doc.xml") (: Works, but has hardcoded the database :) > > ==8<========================= > > let $db := request:parameter('param1') > return > db:add($db, <a/>, "doc.xml") (: Works, but had to pass the database name as a > parameter :) > > ==8<========================= > > db:add(., <a/>, "doc.xml") (: Doesn't work, and I didn't expect it to, but > would be ideal :) > > Is there any way to achieve this? There isn't anyway of converting the > current context into an expression containing the database (and path) is > there? > > Thanks, > Luke > > -----Original Message----- > From: Christian Grün <christian.gr...@gmail.com> > Sent: Tuesday, 21 January 2020 6:38 PM > To: ERRINGTON Luke <luke.erring...@sydac.com> > Cc: basex-talk@mailman.uni-konstanz.de > Subject: Re: [basex-talk] Server-side XQuery scripts understanding their > "context" > > Hi Luke, > > > However, when I execute an XQuery I would like it to run on a particular > > database. Is there anyway to achieve this without passing the database as > > an argument to the query? > > If you address a database in your URL, it will be bound to the context of > your query, which can be obtained via a simple dot (.). For example, run the > following query to get the number of documents in your 'Test' database: > > http://localhost:8984/rest/Test?query=count(.) > > I have added another example in our documentation [1]. The given query can > also be written to a file and evaluated with 'run'. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/REST#GET_Method