1 package Catalyst::Controller::REST;
5 use base 'Catalyst::Controller';
6 use Params::Validate qw(:all);
8 __PACKAGE__->mk_accessors(qw(serialize));
13 'stash_key' => 'rest',
15 'text/x-yaml' => 'YAML',
16 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
21 sub begin : ActionClass('Deserialize') {}
23 sub end : ActionClass('Serialize') { }
25 # You probably want to refer to the HTTP 1.1 Spec for these; they should
26 # conform as much as possible.
28 # ftp://ftp.isi.edu/in-notes/rfc2616.txt
35 location => { type => SCALAR | OBJECT },
36 entity => { optional => 1 },
41 if (ref($p{'location'})) {
42 $location = $p{'location'}->as_string;
44 $c->response->status(201);
45 $c->response->header('Location' => $location);
46 $self->_set_entity($c, $p{'entity'});
59 $c->response->status(200);
60 $self->_set_entity($c, $p{'entity'});
64 sub status_bad_request {
69 message => { type => SCALAR },
73 $c->response->status(400);
74 $self->_set_entity($c, { error => $p{'message'} });
78 sub status_not_found {
83 message => { type => SCALAR },
87 $c->response->status(404);
88 $self->_set_entity($c, { error => $p{'message'} });
96 if (defined($entity)) {
97 $c->stash->{$self->config->{'serialize'}->{'stash_key'}} = $entity;