operly decoded (we recommend UTF-8 of course). For output, the default is C<application/json> encoded with L<JSON::XS>. Both the input and output types can be modified, although this is only partially
the following methods on the context object:
=over
=item C<respond>
The respond method sends a JSON response, the contents of which are encoded from the first argument:
$c->respond({ a => 1, b
ault message ("Forbidden" in this case) and the JSON body will be C<{"error":"access denied"}>.
This works too, except the value of C<error> in the JSON body of the response will just be "HTTP code 4
;
use common::sense;
use Plack::Request::WithEncoding;
use Plack::Response;
use Log::Defer;
use JSON::XS;
use Data::Dumper;
sub new {
my ($class, %args) = @_;
my $self = \%args;
bless
eval { encode_json($msg) };
if ($@) {
$encoded_msg = eval { encode_json(_json_clean($msg)) };
if ($@) {
$encoded_msg = "Failed to JSON clean: " . Dum
}) {
$self->logger->warn("sending JSON error: $body->{error}");
}
return $self->respond_raw($http_code // 200, 'application/json', encode_json($body));
}
sub done {
die shift->