Hi Mickael,
Welcome to the list.
Your RESTXQ code looks correct to me; I have just tested it locally; the client request of "http://localhost:8984/plugins/test.txt" gives me only the file contents.
Do you use a recent version of BaseX? How did you test your RESTXQ endpoint?
Salutations, Christian
On Thu, Mar 19, 2020 at 9:35 AM Mickael Desfrenes mickael.desfrenes@unicaen.fr wrote:
Hello,
This is my first post here, I hope this is the right list for such questions.
I am using RestXQ to send assets to the browser. Given that I want to control some headers ("expires" and such), I thought I could use RestXQ custom responses.
Here's what I came up with:
declare %rest:path("/plugins/{$filePath=.*}") function max.file:pluginUIFile($filePath as xs:string){ let $path := file:parent(file:parent(static-base-uri())) || "/plugins/" || $filePath return (<rest:response> <http:response status="200"> <http:header name="expires" value="Wed, 21 Oct 2222 07:28:00 GMT"/> </http:response> </rest:response>, max.util:rawFile($path)) };
The HTTP response does have the wanted header. However, the body has some unwanted XML at the top:
<rest:response xmlns:rest="http://exquery.org/ns/restxq%22%3E <http:response xmlns:http="http://expath.org/ns/http-client%22/%3E <output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization%22%3E <output:media-type value="text/ecmascript"/> </output:serialization-parameters> </rest:response> class DocumentBasket { constructor(basket_id = "basket") { this.storage = localStorage; this.basket_id = basket_id; }
_fetch_basket_data() { let basket_data = this.storage.getItem(this.basket_id); if (basket_data === null) { basket_data = []; } else { basket_data = JSON.parse(basket_data); } return basket_data; }
[more js below]
Since I'm fairly new to the basex framework, I'm not sure if I'm doing something wrong or if it's some kind of bug.
Thank you for your help,
M. Desfrênes