Merge in object_split functionality
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RPC.pm
CommitLineData
d2739840 1package Catalyst::Controller::DBIC::API::RPC;
2#ABSTRACT: Provides an RPC interface to DBIx::Class
3
4use Moose;
5BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
6
7__PACKAGE__->config(
8 'action' => { object => { 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
19Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
20
21By default provides the following endpoints:
22
23 $base/create
24 $base/list
609916e5 25 $base/id/[identifier]
d2739840 26 $base/id/[identifier]/delete
27 $base/id/[identifier]/update
28
29Where $base is the URI described by L</setup>, the chain root of the controller.
30
31=method_protected setup
32
33Chained: override
34PathPart: override
35CaptureArgs: 0
36
37As 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
d2739840 44=cut
45
46sub 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
609916e5 55Chained: L</object_no_id>
d2739840 56PathPart: create
57CaptureArgs: 0
58
59Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
60
61=cut
62
609916e5 63sub create :Chained('object_no_id') :PathPart('create') :Args(0)
d2739840 64{
65 my ($self, $c) = @_;
d2739840 66 $c->forward('update_or_create');
67}
68
69=method_protected list
70
609916e5 71Chained: L</deserialize>
d2739840 72PathPart: list
73CaptureArgs: 0
74
75Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
76
77=cut
78
609916e5 79sub list :Chained('deserialize') :PathPart('list') :Args(0) {
d2739840 80 my ($self, $c) = @_;
81
82 $self->next::method($c);
83}
84
609916e5 85=method_protected item
86
87Chained: L</object_with_id>
88PathPart: ''
89Args: 0
90
91Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>.
92
93=cut
94
95sub item :Chained('object_with_id') :PathPart('') :Args(0) {
96 my ($self, $c) = @_;
97
98 $c->forward('view');
99}
100
d2739840 101=method_protected update
102
609916e5 103Chained: L</object_with_id>
d2739840 104PathPart: update
609916e5 105Args: 0
d2739840 106
107Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
108
109=cut
110
609916e5 111sub update :Chained('object_with_id') :PathPart('update') :Args(0) {
112 my ($self, $c) = @_;
d2739840 113
114 $c->forward('update_or_create');
115}
116
117=method_protected delete
118
609916e5 119Chained: L</object_with_id>
d2739840 120PathPart: delete
609916e5 121Args: 0
d2739840 122
123Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
124
125=cut
126
609916e5 127sub delete :Chained('object_with_id') :PathPart('delete') :Args(0)
128{
129 my ($self, $c) = @_;
130 $self->next::method($c);
131}
d2739840 132
609916e5 133=method_protected update_bulk
134
135Chained: L</object_no_id>
136PathPart: update
137Args: 0
138
139Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects.
140
141=cut
142
143sub update_bulk :Chained('object_no_id') :PathPart('update') :Args(0)
144{
145 my ($self, $c) = @_;
146 $c->forward('update_or_create');
147}
148
149=method_protected delete_bulk
150
151Chained: L</object_no_id>
152PathPart: delete
153Args: 0
154
155Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects.
156
157=cut
158
159sub delete_bulk :Chained('object_no_id') :PathPart('delete') :Args(0)
160{
161 my ($self, $c) = @_;
162 $self->next::method($c);
d2739840 163}
164
1651;