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