=back
-By default, L<Catalyst::Controller::REST> will return a C<415 Unsupported Media Type> response if an attempt to use an unsupported content-type is made. You
-can ensure that something is always returned by setting the C<default> config
-option:
+By default, L<Catalyst::Controller::REST> will return a C<415 Unsupported Media Type>
+response if an attempt to use an unsupported content-type is made. You
+can ensure that something is always returned by setting the C<default>
+config option:
- __PACKAGE__->config->{'serialize'}->{'default'} = 'YAML';
+ __PACKAGE__->config->{'default'} = 'text/x-yaml';
-Would make it always fall back to YAML.
+Would make it always fall back to the serializer plugin defined for text/x-yaml.
Implementing new Serialization formats is easy! Contributions
are most welcome! See L<Catalyst::Action::Serialize> and
__PACKAGE__->mk_accessors(qw(serialize));
__PACKAGE__->config(
- serialize => {
'stash_key' => 'rest',
'map' => {
'text/html' => 'YAML::HTML',
'text/x-config-general' => [ 'Data::Serializer', 'Config::General' ],
'text/x-php-serialization' => [ 'Data::Serializer', 'PHP::Serialization' ],
},
- }
);
sub begin : ActionClass('Deserialize') {
my %p = validate( @_, { message => { type => SCALAR }, }, );
$c->response->status(400);
- $c->log->debug( "Status Bad Request: " . $p{'message'} );
+ $c->log->debug( "Status Bad Request: " . $p{'message'} ) if $c->debug;
$self->_set_entity( $c, { error => $p{'message'} } );
return 1;
}
my %p = validate( @_, { message => { type => SCALAR }, }, );
$c->response->status(404);
- $c->log->debug( "Status Not Found: " . $p{'message'} );
+ $c->log->debug( "Status Not Found: " . $p{'message'} ) if $c->debug;
$self->_set_entity( $c, { error => $p{'message'} } );
return 1;
}
my $c = shift;
my $entity = shift;
if ( defined($entity) ) {
- $c->stash->{ $self->config->{'serialize'}->{'stash_key'} } = $entity;
+ $c->stash->{ $self->{'stash_key'} } = $entity;
}
return 1;
}