Peter Karman > CatalystX-CRUD > CatalystX::CRUD::REST

Download:
CatalystX-CRUD-0.56.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.56   Source  

NAME ^

CatalystX::CRUD::REST - RESTful CRUD controller

SYNOPSIS ^

    # create a controller
    package MyApp::Controller::Foo;
    use strict;
    use base qw( CatalystX::CRUD::REST );
    use MyForm::Foo;
    
    __PACKAGE__->config(
        form_class              => 'MyForm::Foo',
        init_form               => 'init_with_foo',
        init_object             => 'foo_from_form',
        default_template        => 'path/to/foo/edit.tt',
        model_name              => 'Foo',
        primary_key             => 'id',
        view_on_single_result   => 0,
        page_size               => 50,
        enable_rpc_compat       => 0,
    );
                    
    1;
    
    # now you can manage Foo objects using your MyForm::Foo form class
    # with URIs at:
    #  foo/<pk>
    # and use the HTTP method name to indicate the appropriate action.
    # POST      /foo                -> create new record
    # GET       /foo                -> list all records
    # PUT       /foo/<pk>           -> update record
    # DELETE    /foo/<pk>           -> delete record
    # GET       /foo/<pk>           -> view record
    # GET       /foo/<pk>/edit_form -> edit record form
    # GET       /foo/create_form    -> create record form

DESCRIPTION ^

CatalystX::CRUD::REST is a subclass of CatalystX::CRUD::Controller. Instead of calling RPC-style URIs, the REST API uses the HTTP method name to indicate the action to be taken.

See CatalystX::CRUD::Controller for more details on configuration.

The REST API is designed with identical configuration options as the RPC-style Controller API, so that you can simply change your @ISA chain and enable REST features for your application.

IMPORTANT: If you are using a CatalystX::CRUD::REST subclass in your application, it is important to add the following to your main MyApp.pm file, just after the setup() call:

 __PACKAGE__->setup();
 
 # add these 3 lines
 use MRO::Compat;
 use mro 'c3';
 Class::C3::initialize();

This is required for Class::C3 to resolve the inheritance chain correctly, especially in the case where your app is subclassing more than one CatalystX::CRUD::Controller::* class.

METHODS ^

edit_form

Acts just like edit() in base Controller class, but with a RESTful name.

create_form

Acts just like create() in base Controller class, but with a RESTful name.

create

Redirects to create_form().

rest

Attribute: Path Args

Calls the appropriate method based on the HTTP method name.

default

Attribute: Private

Returns 404 status. In theory, this action is never reached, and if it is, will log an error. It exists only for debugging purposes.

req_method( context )

Internal method. Returns the HTTP method name, allowing POST to serve as a tunnel when the _http_method or x-tunneled-method param is present. Since most browsers do not support PUT or DELETE HTTP methods, you can use the special param to tunnel the desired HTTP method and then POST instead.

edit( context )

Overrides base method to disable chaining.

view( context )

Overrides base method to disable chaining.

save( context )

Overrides base method to disable chaining.

rm( context )

Overrides base method to disable chaining.

remove( context )

Overrides base method to disable chaining.

add( context )

Overrides base method to disable chaining.

view_related( context )

Overrides base method to disable chaining.

list_related( context )

Overrides base method to disable chaining.

delete( context )

Overrides base method to disable chaining.

read( context )

Overrides base method to disable chaining.

update( context )

Overrides base method to disable chaining.

postcommit( context, object )

Overrides base method to redirect to REST-style URL.

new

Overrides base method just to call next::method to ensure config() gets merged correctly.

AUTHOR ^

Peter Karman, <perl at peknet.com>

BUGS ^

Please report any bugs or feature requests to bug-catalystx-crud at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc CatalystX::CRUD

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2008 Peter Karman, all rights reserved.

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

syntax highlighting: