1 package Catalyst::Controller::DBIC::API::REST;
3 #ABSTRACT: Provides a REST interface to DBIx::Class
5 BEGIN { extends 'Catalyst::Controller::DBIC::API'; }
8 'default' => 'application/json',
9 'stash_key' => 'response',
11 'application/x-www-form-urlencoded' => 'JSON',
12 'application/json' => 'JSON',
18 Provides a REST style API interface to the functionality described in
19 L<Catalyst::Controller::DBIC::API>.
21 By default provides the following endpoints:
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)
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>
30 =method_protected setup
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
40 These must be defined in order for the controller to function.
42 The neatest way is normally to define these using the controller's config.
45 ( action => { setup => { PathPart => 'track', Chained => '/api/rest/rest_base' } },
49 =method_protected update_or_create_objects
51 Chained: L</objects_no_id>
56 Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
60 sub update_or_create_objects : POST PUT Chained('objects_no_id') PathPart('')
62 my ( $self, $c ) = @_;
63 $self->update_or_create($c);
66 =method_protected delete_many_objects
68 Chained: L</objects_no_id>
73 Calls L<Catalyst::Controller::DBIC::API/delete>.
77 sub delete_many_objects : DELETE Chained('objects_no_id') PathPart('')
79 my ( $self, $c ) = @_;
83 =method_protected list_objects
85 Chained: L</objects_no_id>
90 Calls L<Catalyst::Controller::DBIC::API/list>.
94 sub list_objects : GET Chained('objects_no_id') PathPart('') Args(0) {
95 my ( $self, $c ) = @_;
99 =method_protected update_or_create_one_object
101 Chained: L</object_with_id>
106 Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
110 sub update_or_create_one_object : POST PUT Chained('object_with_id')
111 PathPart('') Args(0) {
112 my ( $self, $c ) = @_;
113 $self->update_or_create($c);
116 =method_protected delete_one_object
118 Chained: L</object_with_id>
123 Calls L<Catalyst::Controller::DBIC::API/delete>.
127 sub delete_one_object : DELETE Chained('object_with_id') PathPart('') Args(0)
129 my ( $self, $c ) = @_;
133 =method_protected list_one_object
135 Chained: L</object_with_id>
140 Calls L<Catalyst::Controller::DBIC::API/item>.
144 sub list_one_object : GET Chained('object_with_id') PathPart('') Args(0) {
145 my ( $self, $c ) = @_;