Start proper dispatch chaining for objects with and without identifiers
[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
25 $base/id/[identifier]/delete
26 $base/id/[identifier]/update
27
28Where $base is the URI described by L</setup>, the chain root of the controller.
29
30=method_protected setup
31
32Chained: override
33PathPart: override
34CaptureArgs: 0
35
36As 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.
37
38 __PACKAGE__->config
39 ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } },
40 ...
41 );
42
43=method_protected object
44
45Chained: L</setup>
46PathPart: object
47CaptureArgs: 1
48
49Provides an chain point to the functionality described in L<Catalyst::Controller::DBIC::API/object>. All object level endpoints should use this as their chain root.
50
51=cut
52
53sub index : Chained('setup') PathPart('') Args(0) {
54 my ( $self, $c ) = @_;
55
56 $self->push_error($c, { message => 'Not implemented' });
57 $c->res->status( '404' );
58}
59
60=method_protected create
61
62Chained: L</setup>
63PathPart: create
64CaptureArgs: 0
65
66Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
67
68=cut
69
70sub create :Chained('setup') :PathPart('create') :Args(0)
71{
72 my ($self, $c) = @_;
73 $c->forward('object');
74 return if $self->get_errors($c);
75 $c->forward('update_or_create');
76}
77
78=method_protected list
79
80Chained: L</setup>
81PathPart: list
82CaptureArgs: 0
83
84Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>.
85
86=cut
87
88sub list :Chained('setup') :PathPart('list') :Args(0) {
89 my ($self, $c) = @_;
90
91 $self->next::method($c);
92}
93
94=method_protected update
95
96Chained: L</object>
97PathPart: update
98CaptureArgs: 0
99
100Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>.
101
102=cut
103
104sub update :Chained('object') :PathPart('update') :Args(0) {
105 my ($self, $c) = @_;
106
107 $c->forward('update_or_create');
108}
109
110=method_protected delete
111
112Chained: L</object>
113PathPart: delete
114CaptureArgs: 0
115
116Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/delete>.
117
118=cut
119
120sub delete :Chained('object') :PathPart('delete') :Args(0) {
121 my ($self, $c) = @_;
122
123 $self->next::method($c);
124}
125
1261;