NAME
Mojolicious::Plugin::RESTRoutes - routing helpers for RESTful operations
VERSION
version 0.0100065
DESCRIPTION
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.
EXTENDS
METHODS
register
Adds the routing helpers. Is called by Mojolicious.
MOJOLICIOUS SHORTCUTS
rest_routes
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
- name
-
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).
- readonly
-
(optional) if set to 1, no create/update/delete routes will be created
- controller
-
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() # ...
AUTHOR
Jens Berthold <cpan-mp-restroutes@jebecs.de>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Jens Berthold.
This is free software, licensed under:
The MIT (X11) License