package Apache2::REST::Writer::json ;
use strict ;
use JSON::XS ;
use Data::Dumper ;
=head1 NAME
Apache2::REST::Writer::json - Apache2::REST::Response Writer for json
=cut
=head2 new
=cut
sub
ication/json' ;
}
=head2 asBytes
Returns the response as json UTF8 bytes for output.
=cut
sub asBytes{
my ($self, $resp ) = @_ ;
#Shallow unblessed copy of response
# JSON wont o
utput blessed object not implementing the TO_JSON request
my %resp = %$resp ;
my $coder = JSON::XS->new->allow_blessed(0)->utf8;
## These are bytes. This is correct.
return $coder->enc
{} , $class;
}
=head2 mimeType
Getter
=cut
sub mimeType{
# Ideal
#return 'application/json' ;
# Reality
return 'application/x-perl';
}
=head2 asBytes
Returns the response as yaml
package Apache2::REST::Writer::bin ;
use strict ;
use JSON::XS ;
use Data::Dumper ;
=head1 NAME
Apache2::REST::Writer::bin - Apache2::REST::Response Writer for binary
=head1 DESCRIPTION
This wri
->binMimeType() ;
}
return 'application/bin' ;
}
=head2 asBytes
Returns the response as json UTF8 bytes for output.
=cut
sub asBytes{
my ($self, $resp ) = @_ ;
return $resp->
from the fmt parameter. For instance '?fmt=json'
extension - With this method, the writer is selected from the url extension. For instance : '/test.json'
header - With this method, the writer
When using 'param' (default) ask for json format like this: http://localhost/test/?fmt=json
When using 'extension' : http://localhost/test.json
=head3 Apache2RESTWriterDefault
Sets the d
efault writer. If ommitted, the default is C<xml>. Available writers are C<xml>, C<json>, C<yaml>, C<perl>, C<bin>
=head2 command line REST client
This module comes with a commandline REST client to