Renamed Visitor to Validator::Visitor to conform with Data::DPath::Validator and...
[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 =method_protected create
47
48 Chained: L</objects_no_id>
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
56 sub create :Chained('objects_no_id') :PathPart('create') :Args(0)
57 {
58         my ($self, $c) = @_;
59     $self->update_or_create($c);
60 }
61
62 =method_protected list
63
64 Chained: L</deserialize>
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
72 sub list :Chained('deserialize') :PathPart('list') :Args(0)
73 {
74         my ($self, $c) = @_;
75     $self->next::method($c);
76 }
77
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
88 sub item :Chained('object_with_id') :PathPart('') :Args(0)
89 {
90     my ($self, $c) = @_;
91     $self->next::method($c);
92 }
93
94 =method_protected update
95
96 Chained: L</object_with_id>
97 PathPart: update
98 Args: 0
99
100 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
101
102 =cut
103
104 sub update :Chained('object_with_id') :PathPart('update') :Args(0)
105 {
106     my ($self, $c) = @_;
107     $self->update_or_create($c);
108 }
109
110 =method_protected delete
111
112 Chained: L</object_with_id>
113 PathPart: delete
114 Args: 0
115
116 Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
117
118 =cut
119
120 sub delete :Chained('object_with_id') :PathPart('delete') :Args(0)
121 {
122     my ($self, $c) = @_;
123     $self->next::method($c);
124 }
125
126 =method_protected update_bulk
127
128 Chained: L</objects_no_id>
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
136 sub update_bulk :Chained('objects_no_id') :PathPart('update') :Args(0)
137 {
138     my ($self, $c) = @_;
139     $self->update_or_create($c);
140 }
141
142 =method_protected delete_bulk
143
144 Chained: L</objects_no_id>
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
152 sub delete_bulk :Chained('objects_no_id') :PathPart('delete') :Args(0)
153 {
154     my ($self, $c) = @_;
155     $self->delete($c);
156 }
157
158 1;