perltidy all classes
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / REST.pm
CommitLineData
d2739840 1package Catalyst::Controller::DBIC::API::REST;
2
3#ABSTRACT: Provides a REST interface to DBIx::Class
4use Moose;
5BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
6
7__PACKAGE__->config(
8 'default' => 'application/json',
9 'stash_key' => 'response',
10 'map' => {
11 'application/x-www-form-urlencoded' => 'JSON',
12 'application/json' => 'JSON',
8ea592cb 13 }
14);
d2739840 15
16=head1 DESCRIPTION
17
406086f3 18Provides a REST style API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
d2739840 19
20By default provides the following endpoints:
21
609916e5 22 $base (operates on lists of objects and accepts GET, PUT, POST and DELETE)
23 $base/[identifier] (operates on a single object and accepts GET, PUT, POST and DELETE)
d2739840 24
25Where $base is the URI described by L</setup>, the chain root of the controller, and the request type will determine the L<Catalyst::Controller::DBIC::API> method to forward.
26
27=method_protected setup
28
29Chained: override
30PathPart: override
31CaptureArgs: 0
32
33As described in L<Catalyst::Controller::DBIC::API/setup>, this action is the chain root of the controller but has no pathpart or chain parent defined by default, so these must be defined in order for the controller to function. The neatest way is normally to define these using the controller's config.
34
35 __PACKAGE__->config
406086f3 36 ( action => { setup => { PathPart => 'track', Chained => '/api/rest/rest_base' } },
d2739840 37 ...
38 );
39
b66d4310 40=method_protected update_or_create_objects
d2739840 41
533075c7 42Chained: L</objects_no_id>
d2739840 43PathPart: none
b66d4310 44Args: 0
45Method: POST/PUT
d2739840 46
b66d4310 47Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
d2739840 48
49=cut
50
8ea592cb 51sub update_or_create_objects : POST PUT Chained('objects_no_id') PathPart('')
52 Args(0) {
53 my ( $self, $c ) = @_;
3d85db11 54 $self->update_or_create($c);
d2739840 55}
56
b66d4310 57=method_protected delete_many_objects
58
59Chained: L</objects_no_id>
60PathPart: none
61Args: 0
62Method: DELETE
63
64Calls L<Catalyst::Controller::DBIC::API/delete>.
65
66=cut
67
8ea592cb 68sub delete_many_objects : DELETE Chained('objects_no_id') PathPart('')
69 Args(0) {
70 my ( $self, $c ) = @_;
3d85db11 71 $self->delete($c);
d2739840 72}
73
b66d4310 74=method_protected list_objects
75
76Chained: L</objects_no_id>
77PathPart: none
78Args: 0
79Method: GET
80
81Calls L<Catalyst::Controller::DBIC::API/list>.
82
83=cut
84
8ea592cb 85sub list_objects : GET Chained('objects_no_id') PathPart('') Args(0) {
86 my ( $self, $c ) = @_;
3d85db11 87 $self->list($c);
d2739840 88}
89
b66d4310 90=method_protected update_or_create_one_object
609916e5 91
92Chained: L</object_with_id>
93PathPart: none
b66d4310 94Args: 0
95Method: POST/PUT
609916e5 96
b66d4310 97Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
609916e5 98
99=cut
100
8ea592cb 101sub update_or_create_one_object : POST PUT Chained('object_with_id')
102 PathPart('') Args(0) {
103 my ( $self, $c ) = @_;
3d85db11 104 $self->update_or_create($c);
8cf0b66a 105}
106
b66d4310 107=method_protected delete_one_object
108
109Chained: L</object_with_id>
110PathPart: none
111Args: 0
112Method: DELETE
113
114Calls L<Catalyst::Controller::DBIC::API/delete>.
115
116=cut
117
26e9dcd6 118sub delete_one_object : DELETE Chained('object_with_id') PathPart('') Args(0)
8cf0b66a 119{
8ea592cb 120 my ( $self, $c ) = @_;
3d85db11 121 $self->delete($c);
8cf0b66a 122}
123
b66d4310 124=method_protected list_one_object
125
126Chained: L</object_with_id>
127PathPart: none
128Args: 0
129Method: GET
130
131Calls L<Catalyst::Controller::DBIC::API/item>.
132
133=cut
134
8ea592cb 135sub list_one_object : GET Chained('object_with_id') PathPart('') Args(0) {
136 my ( $self, $c ) = @_;
3d85db11 137 $self->item($c);
8cf0b66a 138}
139
d2739840 1401;