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