Version 2.008001
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / REST.pm
CommitLineData
d2739840 1package Catalyst::Controller::DBIC::API::REST;
2
3#ABSTRACT: Provides a REST interface to DBIx::Class
4use Moose;
5BEGIN { 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 18Provides a REST style API interface to the functionality described in
19L<Catalyst::Controller::DBIC::API>.
d2739840 20
21By 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 26Where $base is the URI described by L</setup>, the chain root of the controller
27and the request type will determine the L<Catalyst::Controller::DBIC::API>
28method to forward.
d2739840 29
30=method_protected setup
31
32Chained: override
33PathPart: override
34CaptureArgs: 0
35
c0c8e1c6 36As described in L<Catalyst::Controller::DBIC::API/setup>, this action is the
37chain root of the controller but has no pathpart or chain parent defined by
38default.
39
40These must be defined in order for the controller to function.
41
42The 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 51Chained: L</objects_no_id>
d2739840 52PathPart: none
b66d4310 53Args: 0
54Method: POST/PUT
d2739840 55
b66d4310 56Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
d2739840 57
58=cut
59
8ea592cb 60sub 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
68Chained: L</objects_no_id>
69PathPart: none
70Args: 0
71Method: DELETE
72
73Calls L<Catalyst::Controller::DBIC::API/delete>.
74
75=cut
76
8ea592cb 77sub 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
85Chained: L</objects_no_id>
86PathPart: none
87Args: 0
88Method: GET
89
90Calls L<Catalyst::Controller::DBIC::API/list>.
91
92=cut
93
8ea592cb 94sub 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
101Chained: L</object_with_id>
102PathPart: none
b66d4310 103Args: 0
104Method: POST/PUT
609916e5 105
b66d4310 106Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
609916e5 107
108=cut
109
8ea592cb 110sub 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
118Chained: L</object_with_id>
119PathPart: none
120Args: 0
121Method: DELETE
122
123Calls L<Catalyst::Controller::DBIC::API/delete>.
124
125=cut
126
26e9dcd6 127sub 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
135Chained: L</object_with_id>
136PathPart: none
137Args: 0
138Method: GET
139
140Calls L<Catalyst::Controller::DBIC::API/item>.
141
142=cut
143
8ea592cb 144sub list_one_object : GET Chained('object_with_id') PathPart('') Args(0) {
145 my ( $self, $c ) = @_;
3d85db11 146 $self->item($c);
8cf0b66a 147}
148
d2739840 1491;