Commit | Line | Data |
d2739840 |
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( |
406086f3 |
8 | 'action' => { object_with_id => { PathPart => 'id' } }, |
d2739840 |
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 | |
406086f3 |
19 | Provides an RPC API interface to the functionality described in L<Catalyst::Controller::DBIC::API>. |
d2739840 |
20 | |
21 | By 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 | |
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 |
406086f3 |
40 | ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } }, |
d2739840 |
41 | ... |
42 | ); |
43 | |
d2739840 |
44 | =cut |
45 | |
d2739840 |
46 | =method_protected create |
47 | |
533075c7 |
48 | Chained: L</objects_no_id> |
d2739840 |
49 | PathPart: create |
50 | CaptureArgs: 0 |
51 | |
52 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>. |
53 | |
54 | =cut |
55 | |
406086f3 |
56 | sub create :Chained('objects_no_id') :PathPart('create') :Args(0) |
d2739840 |
57 | { |
58 | my ($self, $c) = @_; |
3d85db11 |
59 | $self->update_or_create($c); |
d2739840 |
60 | } |
61 | |
62 | =method_protected list |
63 | |
609916e5 |
64 | Chained: L</deserialize> |
d2739840 |
65 | PathPart: list |
66 | CaptureArgs: 0 |
67 | |
68 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>. |
69 | |
70 | =cut |
71 | |
406086f3 |
72 | sub list :Chained('deserialize') :PathPart('list') :Args(0) |
533075c7 |
73 | { |
d2739840 |
74 | my ($self, $c) = @_; |
533075c7 |
75 | $self->next::method($c); |
d2739840 |
76 | } |
77 | |
609916e5 |
78 | =method_protected item |
79 | |
80 | Chained: L</object_with_id> |
81 | PathPart: '' |
82 | Args: 0 |
83 | |
84 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/item>. |
85 | |
86 | =cut |
87 | |
406086f3 |
88 | sub item :Chained('object_with_id') :PathPart('') :Args(0) |
533075c7 |
89 | { |
609916e5 |
90 | my ($self, $c) = @_; |
533075c7 |
91 | $self->next::method($c); |
609916e5 |
92 | } |
93 | |
d2739840 |
94 | =method_protected update |
95 | |
609916e5 |
96 | Chained: L</object_with_id> |
d2739840 |
97 | PathPart: update |
609916e5 |
98 | Args: 0 |
d2739840 |
99 | |
100 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>. |
101 | |
102 | =cut |
103 | |
406086f3 |
104 | sub update :Chained('object_with_id') :PathPart('update') :Args(0) |
533075c7 |
105 | { |
609916e5 |
106 | my ($self, $c) = @_; |
3d85db11 |
107 | $self->update_or_create($c); |
d2739840 |
108 | } |
109 | |
110 | =method_protected delete |
111 | |
609916e5 |
112 | Chained: L</object_with_id> |
d2739840 |
113 | PathPart: delete |
609916e5 |
114 | Args: 0 |
d2739840 |
115 | |
116 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>. |
117 | |
118 | =cut |
119 | |
406086f3 |
120 | sub delete :Chained('object_with_id') :PathPart('delete') :Args(0) |
609916e5 |
121 | { |
122 | my ($self, $c) = @_; |
123 | $self->next::method($c); |
124 | } |
d2739840 |
125 | |
609916e5 |
126 | =method_protected update_bulk |
127 | |
533075c7 |
128 | Chained: L</objects_no_id> |
609916e5 |
129 | PathPart: update |
130 | Args: 0 |
131 | |
132 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create> for multiple objects. |
133 | |
134 | =cut |
135 | |
406086f3 |
136 | sub update_bulk :Chained('objects_no_id') :PathPart('update') :Args(0) |
609916e5 |
137 | { |
138 | my ($self, $c) = @_; |
3d85db11 |
139 | $self->update_or_create($c); |
609916e5 |
140 | } |
141 | |
142 | =method_protected delete_bulk |
143 | |
533075c7 |
144 | Chained: L</objects_no_id> |
609916e5 |
145 | PathPart: delete |
146 | Args: 0 |
147 | |
148 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete> for multiple objects. |
149 | |
150 | =cut |
151 | |
406086f3 |
152 | sub delete_bulk :Chained('objects_no_id') :PathPart('delete') :Args(0) |
609916e5 |
153 | { |
154 | my ($self, $c) = @_; |
a1f71064 |
155 | $self->delete($c); |
d2739840 |
156 | } |
157 | |
158 | 1; |