(Continuing this discussion on [email protected] - started at http://n3.nabble.com/Client-JSon-Calls-td139540.html#a139540) > On Wed, Jan 27, 2010 at 10:21, Vidar Ramdal <[email protected]> wrote: >> It would be nice if there was a way to get JSON output from the >> standard SlngPostServlet, so that way we could leverage current >> SlingPostOperations. I have looked into it briefly. The HtmlResponse >> object that is passed to SlingPostOperations is a bit of a turn-off in >> this sense, but AFAICT only HtmlResponse.send() actually produces >> HTML. >> We could abstract HtmlResponse to some output-agnostic Response >> object, and then let SlingPostServlet decide (how?) which output >> format to return.
On Wed, Jan 27, 2010 at 11:00 AM, Alexander Klimetschek <[email protected]> wrote: > That would be a good idea. The return format should be selected via > the extension (POST foobar.html vs. POST foobar.json). Ah yes, but I think we've been down that road before. What if I actually want to post to a node called /foobar.json (node.getName().equals("foobar.json"))? Maybe we could use the Accept header from the request [1] instead - if the client wants JSON (by specifying application/json in Accept), let it have JSON - if not, return HTML. > But some background on the html response: The reason why it was chosen > is because it is the only response that works, ie. that is parseable > by a javascript browser client, when you post a form to the > SlingPostServlet via a hidden iframe (to post forms in an ajax style > _and_ support file uploads). With an iframe, the response cannot be > json, but only html. The structured html of the sling html response > allows you to parse out the message, status, etc. True, but since the HtmlResponse template is not XML, it's not easily dealt with in e.g. dojo.xhrPost() response handlers. > So in the end, the usable combinations for the SlingPostServlet will > probably be: > form post => html response > json post => json response But if we look for the Accept header (and perhaps also an equivalent request parameter, like :accept), shouldn't we be able to determine response type regardless of form post type? [1] http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3 -- Vidar S. Ramdal <[email protected]> - http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway + 47 22 00 84 00 / +47 21 531941, ext 2070
