[dancer-users] Incorrect attempts to serialize HTML

Andrew Beverley andy at andybev.com
Wed Nov 19 12:27:08 GMT 2014


On Wed, 2014-11-12 at 10:23 +0100, Sawyer X wrote:
> I have two comments left:
> 1. I don't think API requests should be conflated with regular page
> rendering. This should be a clear "I send you JSON, I receive JSON"
> and a clear "I send a request from the browser to render output for
> the user and expect to receive HTML back". There is one exception in
> which you might want to make a JSON request return a rendered HTML
> which you could stick in the page ("template 'parts/box' => {...},
> { layout => undef };") but that's something which would then also get
> serialized and returned back. Imagine an API on the frontend having to
> account for either JSON or HTML, not knowing how an error would be
> returned. It could be a JSON structure with the error or an HTML which
> itself is an error. It's gonna have a bad time. :)

Okay, I think I may be using this wrong. I have the auto-serializer set
to "JSON", which from what I can tell, will look at every response, and
always attempt to serialize the output as long as it is passed a ref,
regardless of the request. So when I'm returning HTML to a HTML request,
it will still try and serialize the data if that HTML happens to be in a
reference (even if it stringifies).

I am assuming that I should instead set the serializer to "Mutable",
which will only try to serialize the appropriate requests.

> 2. If you found the error unhelpful, we should definitely fix it.

I guess my point was that I couldn't think of any way it could be more
helpful, otherwise I would have made a pull request ;-)

> If you could open an issue on Github so we can easily add all the
> context and track it there, we would be more than happy to help.

Thanks. If my comments above stand that I should be (in general) using
the Mutable serializer instead of the JSON serializer, than I'll be
happy to submit some documentation patches.

Thanks,

Andy





More information about the dancer-users mailing list