Mojolicious-Plugin-RESTRoutes
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/RESTRoutes.pm view on Meta::CPAN
use Modern::Perl; # strict, warnings etc.;
package Mojolicious::Plugin::RESTRoutes;
# ABSTRACT: routing helper for RESTful operations
# VERSION
$Mojolicious::Plugin::RESTRoutes::VERSION = '1.0.0';
use Mojo::Base 'Mojolicious::Plugin';
#pod =encoding utf8
#pod
#pod =head1 DESCRIPTION
#pod
#pod This Mojolicious plugin adds a routing helper for
#pod L<REST|http://en.wikipedia.org/wiki/Representational_state_transfer>ful
#pod L<CRUD|http://en.wikipedia.org/wiki/Create,_read,_update_and_delete>
#pod operations via HTTP to the app.
#pod
#pod The routes are intended, but not restricted to be used by AJAX applications.
#pod
#pod =cut
use Lingua::EN::Inflect qw/PL/;
use Mojo::Util qw( camelize );
#pod =method register
#pod
#pod Adds the routing helper (called by Mojolicious).
#pod
#pod =cut
sub register {
my ($self, $app) = @_;
#pod =mojo_short rest_routes
#pod
#pod Can be used to easily generate the needed RESTful routes for a resource.
#pod
#pod my $r = $self->routes;
#pod my $userroute = $r->rest_routes(name => 'user');
#pod
#pod # Installs the following routes (given that $r->namespaces == ['My::Mojo']):
#pod # GET /users --> My::Mojo::User::rest_list()
#pod # POST /users --> My::Mojo::User::rest_create()
#pod # GET /users/:userid --> My::Mojo::User::rest_show()
#pod # PUT /users/:userid --> My::Mojo::User::rest_update()
#pod # DELETE /users/:userid --> My::Mojo::User::rest_remove()
#pod
#pod I<Please note>: the english plural form of the given C<name> attribute will be
#pod used in the route, i.e. "users" instead of "user". If you want to specify
#pod another string, see parameter C<route> below.
#pod
#pod You can also chain C<rest_routes>:
#pod
#pod $userroute->rest_routes(name => 'hat', readonly => 1);
#pod
#pod # Installs the following additional routes:
#pod # GET /users/:userid/hats --> My::Mojo::Hat::rest_list()
#pod # GET /users/:userid/hats/:hatid --> My::Mojo::Hat::rest_show()
#pod
#pod The target controller has to implement the following methods:
#pod
#pod =for :list
#pod * C<rest_list>
( run in 1.639 second using v1.01-cache-2.11-cpan-9581c071862 )