Mojolicious::Plugin::RESTRoutes - routing helpers for RESTful operations
version 0.0100065
This Mojolicious plugin adds some routing helpers for RESTful CRUD operations via HTTP to the app.
The routes are intended, but not restricted to be used by AJAX applications.
Mojolicious::Plugin
Adds the routing helpers. Is called by Mojolicious.
Can be used to easily generate the needed RESTful routes for a resource.
$self->rest_routes(name => 'user'); # Installs the following routes (given that $r->namespaces == ['My::Mojo']): # GET /api/users --> My::Mojo::User::rest_list() # POST /api/users --> My::Mojo::User::rest_create() # GET /api/users/:userid --> My::Mojo::User::rest_show() # PUT /api/users/:userid --> My::Mojo::User::rest_update() # DELETE /api/users/:userid --> My::Mojo::User::rest_remove()
The target controller has to implement the following methods:
rest_list
rest_create
rest_show
rest_update
rest_remove
There are some options to control the route creation:
Parameters
The name of the resource, e.g. a "user", a "book" etc. This name will be used to build the route URL as well as the controller name (see example above).
(optional) if set to 1, no create/update/delete routes will be created
Default behaviour is to use the resource name to build the CamelCase controller name (this is done by Mojolicious::Routes::Route). You can change this by directly specifying the controller's name via the controller attribute.
Note that you have to give the real controller class name (i.e. CamelCased or whatever you class name looks like) including the full namespace.
$self->rest_routes(name => 'user', controller => 'My::Mojo::Person'); # Installs the following routes: # GET /api/users --> My::Mojo::Person::rest_list() # ...
Jens Berthold <cpan-mp-restroutes@jebecs.de>
This software is Copyright (c) 2013 by Jens Berthold.
This is free software, licensed under:
The MIT (X11) License
To install Mojolicious::Plugin::RESTRoutes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::RESTRoutes
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::RESTRoutes
For more information on module installation, please visit the detailed CPAN module installation guide.