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