I have some running code that used the "propitiatory" basex communication method over TCP/IP.
The application was calling basex "client" side (from an Ant task) so this was all fine.

Being used to the SQL paradigm of "preparing" an SQL statement then executing it with different "host variable" values which gives a massive performance advantage over constantly preparing an SQL statement with different literal values plugged in, I chose the same approach for my original XQuery application.

        String partDelete = "declare namespace xyz=\"" + BaseXML.NAMESPACE_URL + "\";\n"
                            + "declare variable $contributor external;\n"
                            + "delete node /xyz:driver[@name=\"" + driver.getDriverName() + "\"]/xyz:part[@contributor=$contributor]";

This statement is executed multiple times from within a loop to delete many "parts", before each execution I perform :-
pd.bind("$contributor", contributor);
pd.execute()

Now we are trying to move the code from being client side to server side, the server is using RESTful interfaces for all external interactions so we are migrating the BaseX interaction to REST too.

I reasoned that if I created a partdelete.xq file on the server that I could then perform a rest request passing in the values of driver and contributor emulating the "host variable" approach.

I created partdelete.xq

module namespace xyz = 'http://my.basex.server.net/xyz';

declare variable $driver external;
declare variable $contributor external;
 delete node /zss:driver[@name=\"$driver"]/zss:part[@contributor=$contributor]

Then (using postman) performed a GET request on

//http:my.basex.server.ne:8984/rest/ TESTDB?run=partdelete.xq&$driver=TESTDRVR&$contributor=LINUX


During my experiments I have managed to get many different error messages, but never got even close to making this work.

Questions:
 o Am I fooling myself that creating a server side .xq file is going to perform better than building a completed query on the client and sending that via REST without "variables"?
 o Is there a way to perform the equivalent "prepare/execute" method from the client without creating a .xq file on the server?
 o Can anyone suggest how I can get the server side .xq file to work?

I also have a query which is executed before the delete to obtain the list of parts to delete.
I was unable to make this work either. The .xq file looked like this

module namespace xyz = 'http://my.basex.server.net/xyz';

declare variable $driver external;
declare variable $contributor external;
for $p in /xyz:driver[@name="$driver"]/xyz:part,
    $o in $p/xyz:part-outputs/xyz:part-output
    where $p/@contributor/data() = $contributor
    return
    data($o/@type)||"/"||data($p/@class)||"/"||data($p/@hostname)

The query works fine from the client side, and since this is only executed once it's no big deal to prefill all the values and dispense with the variables and send it over REST.
I could (I suppose) alternatively use the <variable element as indicated in the BaseX documentation, but it's unclear how that would offer any performance advantage.
Being a lover of consistency I would like to move both queries over to the BaseX server side.

Examples of some of the errors I managed to produce ...
[XPST0081] No namespace declared for 'xyz:driver'
[XPST0003] Library modules cannot be evaluated
[XPDY0002] root(): no context value bound.

Any help, advice or suggestions greatly appreciated.
Mike