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',
17 Provides a REST style API interface to the functionality described in L<Catalyst::Controller::DBIC::API>.
19 By default provides the following endpoints:
21 $base (operates on lists of objects and accepts GET, PUT, POST and DELETE)
22 $base/[identifier] (operates on a single object and accepts GET, PUT, POST and DELETE)
24 Where $base is the URI described by L</setup>, the chain root of the controller, and the request type will determine the L<Catalyst::Controller::DBIC::API> method to forward.
26 =method_protected setup
32 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.
35 ( action => { setup => { PathPart => 'track', Chained => '/api/rest/rest_base' } },
39 =method_protected update_or_create_objects
41 Chained: L</objects_no_id>
46 Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
50 sub update_or_create_objects : Chained('objects_no_id') PathPart('') Does('MatchRequestMethod') Method('POST') Method('PUT') Args(0)
52 my ( $self, $c ) = @_;
53 $self->update_or_create($c);
56 =method_protected delete_many_objects
58 Chained: L</objects_no_id>
63 Calls L<Catalyst::Controller::DBIC::API/delete>.
67 sub delete_many_objects : Chained('objects_no_id') PathPart('') Does('MatchRequestMethod') Method('DELETE') Args(0)
69 my ( $self, $c ) = @_;
73 =method_protected list_objects
75 Chained: L</objects_no_id>
80 Calls L<Catalyst::Controller::DBIC::API/list>.
84 sub list_objects : Chained('objects_no_id') PathPart('') Does('MatchRequestMethod') Method('GET') Args(0)
86 my ( $self, $c ) = @_;
90 =method_protected update_or_create_one_object
92 Chained: L</object_with_id>
97 Calls L<Catalyst::Controller::DBIC::API/update_or_create>.
101 sub update_or_create_one_object : Chained('object_with_id') PathPart('') Does('MatchRequestMethod') Method('POST') Method('PUT') Args(0)
103 my ( $self, $c ) = @_;
104 $self->update_or_create($c);
107 =method_protected delete_one_object
109 Chained: L</object_with_id>
114 Calls L<Catalyst::Controller::DBIC::API/delete>.
118 sub delete_one_object : Chained('object_with_id') PathPart('') Does('MatchRequestMethod') Method('DELETE') Args(0)
120 my ( $self, $c ) = @_;
124 =method_protected list_one_object
126 Chained: L</object_with_id>
131 Calls L<Catalyst::Controller::DBIC::API/item>.
135 sub list_one_object : Chained('object_with_id') PathPart('') Does('MatchRequestMethod') Method('GET') Args(0)
137 my ( $self, $c ) = @_;