NAME

Mojolicious::Plugin::REST - Mojolicious Plugin for RESTful operations

VERSION

version 0.006

SYNOPSIS

# In Mojolicious Application
$self->plugin( 'REST' => { prefix => 'api', version => 'v1' } );

$routes->rest_routes( name => 'Account' );

# Installs following routes:

# /api/v1/accounts             ....  GET     "Account::list_account()"    ^/api/v1/accounts(?:\.([^/]+)$)?
# /api/v1/accounts             ....  POST    "Account::create_account()"  ^/api/v1/accounts(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId  ....  DELETE  "Account::delete_account()"  ^/api/v1/accounts/([^\/\.]+)(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId  ....  GET     "Account::read_account()"    ^/api/v1/accounts/([^\/\.]+)(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId  ....  PUT     "Account::update_account()"  ^/api/v1/accounts/([^\/\.]+)(?:\.([^/]+)$)?


$routes->rest_routes( name => 'Feature', under => 'Account' );

# Installs following routes:

# /api/v1/accounts/:accountId/features             B...  *       "Account::chained()"                 ^/api/v1/accounts/([^\/\.]+)/features
#   +/                                             ....  GET     "Feature::list_account_feature()"    ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/features             B...  *       "Account::chained()"                 ^/api/v1/accounts/([^\/\.]+)/features
#   +/                                             ....  POST    "Feature::create_account_feature()"  ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/features/:featureId  B...  *       "Account::chained()"                 ^/api/v1/accounts/([^\/\.]+)/features/([^\/\.]+)
#   +/                                             ....  DELETE  "Feature::delete_account_feature()"  ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/features/:featureId  B...  *       "Account::chained()"                 ^/api/v1/accounts/([^\/\.]+)/features/([^\/\.]+)
#   +/                                             ....  GET     "Feature::read_account_feature()"    ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/features/:featureId  B...  *       "Account::chained()"                 ^/api/v1/accounts/([^\/\.]+)/features/([^\/\.]+)
#   +/                                             ....  PUT     "Feature::update_account_feature()"  ^(?:\.([^/]+)$)?


$routes->rest_routes( name => 'Product', under => 'Account', types => [qw(ftp ssh)] );

# Installs following routes:

# /api/v1/accounts/:accountId/products      B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products
#   +/                                      ....  GET     "Product::list_account_product()"         ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products      B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products
#   +/                                      ....  POST    "Product::create_account_product()"       ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ftp  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ftp
#   +/                                      ....  DELETE  "Product::Ftp::delete_account_product()"  ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ssh  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ssh
#   +/                                      ....  DELETE  "Product::Ssh::delete_account_product()"  ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ftp  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ftp
#   +/                                      ....  GET     "Product::Ftp::read_account_product()"    ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ssh  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ssh
#   +/                                      ....  GET     "Product::Ssh::read_account_product()"    ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ftp  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ftp
#   +/                                      ....  PUT     "Product::Ftp::update_account_product()"  ^(?:\.([^/]+)$)?
# /api/v1/accounts/:accountId/products/ssh  B...  *       "Account::chained()"                      ^/api/v1/accounts/([^\/\.]+)/products/ssh
#   +/                                      ....  PUT     "Product::Ssh::update_account_product()"  ^(?:\.([^/]+)$)?

DESCRIPTION

Mojolicious::Plugin::REST adds various helpers for RESTful CRUD operations via HTTP to your mojolicious application.

As much as possible, it tries to follow RESTful API Design principles from Apigee.

Used in conjuction with Mojolicious::Controller::REST, this module makes building RESTful application a breeze.

This module is inspired from Mojolicious::Plugin::RESTRoutes.

WARNING

This module is still under development, and it's possible that things may change between releases without warning or deprecations.

MOJOLICIOUS HELPERS

rest_routes

A routes shortcut to easily add RESTful routes for a resource and associations.

MOJOLICIOUS HOOKS

This module installs an before_render application hook, which gurantees JSON output.

Refer Mojolicious::Controller::REST documentation for output format.

Hook installation can be disabled by passing hook => 0 in plugin options. For Example:

$self->plugin( 'REST', prefix => 'api', version => 'v1', hook => 0 );

OPTIONS

Following options can be used to control route creation:

PLUGIN OPTIONS

AUTHOR

Abhishek Shende abhishekisnot@gmail.com

CONTRIBUTORS

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Abhishek Shende.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.