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( |
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 | |
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]/delete |
26 | $base/id/[identifier]/update |
27 | |
28 | Where $base is the URI described by L</setup>, the chain root of the controller. |
29 | |
30 | =method_protected setup |
31 | |
32 | Chained: override |
33 | PathPart: override |
34 | CaptureArgs: 0 |
35 | |
36 | 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. |
37 | |
38 | __PACKAGE__->config |
39 | ( action => { setup => { PathPart => 'track', Chained => '/api/rpc/rpc_base' } }, |
40 | ... |
41 | ); |
42 | |
43 | =method_protected object |
44 | |
45 | Chained: L</setup> |
46 | PathPart: object |
47 | CaptureArgs: 1 |
48 | |
49 | Provides 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 | |
53 | sub 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 | |
62 | Chained: L</setup> |
63 | PathPart: create |
64 | CaptureArgs: 0 |
65 | |
66 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/update_or_create>. |
67 | |
68 | =cut |
69 | |
70 | sub 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 | |
80 | Chained: L</setup> |
81 | PathPart: list |
82 | CaptureArgs: 0 |
83 | |
84 | Provides an endpoint to the functionality described in L<Catalyst::Controller::DBIC::API/list>. |
85 | |
86 | =cut |
87 | |
88 | sub list :Chained('setup') :PathPart('list') :Args(0) { |
89 | my ($self, $c) = @_; |
90 | |
91 | $self->next::method($c); |
92 | } |
93 | |
94 | =method_protected update |
95 | |
96 | Chained: L</object> |
97 | PathPart: update |
98 | CaptureArgs: 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') :PathPart('update') :Args(0) { |
105 | my ($self, $c) = @_; |
106 | |
107 | $c->forward('update_or_create'); |
108 | } |
109 | |
110 | =method_protected delete |
111 | |
112 | Chained: L</object> |
113 | PathPart: delete |
114 | CaptureArgs: 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') :PathPart('delete') :Args(0) { |
121 | my ($self, $c) = @_; |
122 | |
123 | $self->next::method($c); |
124 | } |
125 | |
126 | 1; |