NAME
Catalyst::Model::REST - REST model class for Catalyst
VERSION
version 0.25
SYNOPSIS
Use from a controller
# model
__PACKAGE__->config(
server => 'http://localhost:3000',
type => 'application/json',
clientattrs => {timeout => 5},
);
# controller
sub foo : Local {
my ($self, $c) = @_;
my $res = $c->model('MyData')->post('foo/bar/baz', {foo => 'bar'});
my $code = $res->code;
my $data = $res->data;
...
}
For internal use
# model
sub model_foo {
my ($self) = @_;
my $res = $self->post('foo/bar/baz', {foo => 'bar'});
my $code = $res->code;
my $data = $res->data;
return $data if $code == 200;
}
DESCRIPTION
This Catalyst Model class makes REST connectivety easy.
Catalyst::Model::REST will handle encoding and decoding when using the four HTTP verbs.
GET
PUT
POST
DELETE
Currently Catalyst::Model::REST supports these encodings
application/json
application/x-www-form-urlencoded
application/xml
application/yaml
x-www-form-urlencoded only works for GET and POST, and only for encoding, not decoding.
NAME
Catalyst::Model::REST - REST model class for Catalyst
METHODS
new
Called from Catalyst.
methods
Catalyst::Model::REST implements the standard HTTP 1.1 verbs as methods
post
get
put
delete
All methods take these parameters
url - The REST service
data - The data structure (hashref, arrayref) to send. The data will be encoded
according to the value of the I<type> attribute.
args - hashref with arguments to augment the way the call is handled.
args - the optional argument parameter can have these entries
deserializer - if you KNOW that the content-type of the response is incorrect,
you can supply the correct content type, like
my $res = $self->post('foo/bar/baz', {foo => 'bar'}, {deserializer => 'application/yaml'});
All methods return a Catalyst::Model::REST::Response object.
ATTRIBUTES
Attributes can be set in your application's configuration file. See Catalyst::Manual.
server
Url of the REST server.
e.g. 'http://localhost:3000'
type
Mime content type,
e.g. application/json
clientattrs
Attributes to feed HTTP::Tiny
e.g. {timeout => 10}
AUTHOR
Kaare Rasmussen, <kaare at cpan dot com>
BUGS
Please report any bugs or feature requests to bug-catalyst-model-rest at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Model-REST.
COPYRIGHT & LICENSE
Copyright 2010 Kaare Rasmussen, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
AUTHOR
Kaare Rasmussen <kaare at cpan dot net>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Kaare Rasmussen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.