abcf404d9e48ff3d2f2aba2e1ba9d2fe540d7e60
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RPC.pm
1 package Catalyst::Controller::DBIC::API::RPC;
2 #ABSTRACT: Provides an RPC interface to DBIx::Class
3
4 use Moose;
5 BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
6
7 __PACKAGE__->config(
8     'action'    => { object_with_id => { PathPart => 'id' } }, 
9     'default'   => 'application/json',
10     'stash_key' => 'response',
11     'map'       => {
12         'application/x-www-form-urlencoded' => 'JSON',
13         'application/json'                  => 'JSON',
14     },
15 );
16
17 =head1 DESCRIPTION
18
19 Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>. 
20
21 By default provides the following endpoints:
22
23   $base/create
24   $base/list
25   $base/id/[identifier]
26   $base/id/[identifier]/delete
27   $base/id/[identifier]/update
28
29 Where $base is the URI described by L</setup>, the chain root of the controller.
30
31 =method_protected setup
32
33 Chained: override
34 PathPart: override
35 CaptureArgs: 0
36
37 As 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.
38
39   __PACKAGE__->config
40     ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } }, 
41         ...
42   );
43
44 =cut
45
46 sub index : Chained('setup') PathPart('') Args(0) {
47         my ( $self, $c ) = @_;
48
49         $self->push_error($c, { message => 'Not implemented' });
50         $c->res->status( '404' );
51 }
52
53 =method_protected create
54
55 Chained: L</objects_no_id>
56 PathPart: create
57 CaptureArgs: 0
58
59 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
60
61 =cut
62
63 sub create :Chained('objects_no_id') :PathPart('create')
64 {
65         my ($self, $c) = @_;
66     $c->forward('update_or_create');
67 }
68
69 =method_protected list
70
71 Chained: L</deserialize>
72 PathPart: list
73 CaptureArgs: 0
74
75 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
76
77 =cut
78
79 sub list :Chained('deserialize') :PathPart('list')
80 {
81         my ($self, $c) = @_;
82     $self->next::method($c);
83 }
84
85 =method_protected item
86
87 Chained: L</object_with_id>
88 PathPart: ''
89 Args: 0
90
91 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>.
92
93 =cut
94
95 sub item :Chained('object_with_id') :PathPart('')
96 {
97     my ($self, $c) = @_;
98     $self->next::method($c);
99 }
100
101 =method_protected update
102
103 Chained: L</object_with_id>
104 PathPart: update
105 Args: 0
106
107 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
108
109 =cut
110
111 sub update :Chained('object_with_id') :PathPart('update')
112 {
113     my ($self, $c) = @_;
114     $c->forward('update_or_create');
115 }
116
117 =method_protected delete
118
119 Chained: L</object_with_id>
120 PathPart: delete
121 Args: 0
122
123 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
124
125 =cut
126
127 sub delete :Chained('object_with_id') :PathPart('delete')
128 {
129     my ($self, $c) = @_;
130     $self->next::method($c);
131 }
132
133 =method_protected update_bulk
134
135 Chained: L</objects_no_id>
136 PathPart: update
137 Args: 0
138
139 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects.
140
141 =cut
142
143 sub update_bulk :Chained('objects_no_id') :PathPart('update')
144 {
145     my ($self, $c) = @_;
146     $c->forward('update_or_create');
147 }
148
149 =method_protected delete_bulk
150
151 Chained: L</objects_no_id>
152 PathPart: delete
153 Args: 0
154
155 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects.
156
157 =cut
158
159 sub delete_bulk :Chained('objects_no_id') :PathPart('delete')
160 {
161     my ($self, $c) = @_;
162     $self->next::method($c);
163 }
164
165 1;