A last point I would like to make is that I still find it dubious that the client can specify things in a header (Content Type) that override the way it's porcessed on the server. Isn't this a case of "The server knows best". As a client I just specify that this is JSON and leave it up to the server how to process. If I do that and put an %input:json(...) annotation on the RESTXQ handler it can still be overridden by things specified in the header by the client. But again this probably should be directed at RESTXQ rather than BaseX.
--Marc
On Tue, Aug 4, 2015 at 10:01 AM, Marc van Grootel marc.van.grootel@gmail.com wrote:
Hi Christian,
Super-fast as always ;-)
I'm still struggling though. Couple of points
I have this RESTXQ function that I'm trying to get working.
declare %rest:POST("{$query}") %rest:path("/json") %rest:consumes("application/json") %rest:produces("application/json") %input:json("format=map") function api:json($query) { $query };
I'm posting this as the body (and have Content-Type=application/json)
{"foo": "bar"}
I can get this to work with %input:json format=direct/format=basic but when I change to format=map I still get
[bxerr:BASX0003] Input could not be converted: "POST.xml" (Line 1): No text allowed before root element.
What I want to achieve is not go through JSON > XML parsing but get the same effect as using fn:parse-json() on the incoming JSON and fn:serialize(..., map { 'method': JSON }) on the output.
I can imagine it's the RESTXQ layer itself that preps the args that insists on turning the JSON into XML. Maybe because it hasn't been revamped to fit XQuery 3.1 where we can have native arrays and maps.
A second point regarding format=map. Not sure if this is the correct name as I could be posting "[1,2,3]" which is valid JSON. Does this mean there should be a format=array or would it be better to give a different name for this format.
--Marc
On Mon, Aug 3, 2015 at 6:47 PM, Christian Grün christian.gruen@gmail.com wrote:
…fixed, and available via the latest snapshot [1].
Thanks, Christian
[1] http://files.basex.org/releases/latest
On Mon, Aug 3, 2015 at 5:11 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi Marc,
I'm using Postman. I already had Content-Type = application/json and Accept = application/json. I tried changing it to application/json;format=map
I noticed that you get different result when specify 'format=basic' or 'format=direct':
curl -XPUT -H"Content-Type:application/json;format=basic" -Tinput.json "http://localhost:8984/test"
..so I guess something is going wrong here. I'll dive into this soon.
(btw do you think it's necessary to have the basex/restxq specific pseudo attributes (format= etc) in the HTTP request headers?)
You can also use %input:json(...) if you don't want to specify the format client-side.
Maybe something to forward to Adam Retter / RESTXQ?
So far, the content-type parameter extensions have not been adopted in RESTXQ yet, but feel free to give him an update!
Christian
-- --Marc