The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::OpenResty::Simple - A simple wrapper around WWW::OpenResty

VERSION

This document describes WWW::OpenResty::Simple 0.08 released on September 2, 2008.

SYNOPSIS

    use WWW::OpenResty::Simple;

    my $resty = WWW::OpenResty::Simple->new(
        {
            server => 'http://resty.eeeeworks.org',
            retries => 1 # retry once when failing (default to 0),
        }
    );

    my $res;
    eval {
        $res = $resty->get('/=/version');
    };
    if ($@) { die $@ }
    print Dumper($res);
    # Got:
    # $VAR1 = 'OpenResty 0.1.0 (revision 973) with the ...'

    # The following requires privileges...
    $resty->login('account.Role', 'password');
    $res = $resty->post(
        '/=/model/Comments/~/~',
        {
            author:"agentzh",
            title:"Great post!",
            body:"clapping..."
        }
    );

    # Update the comment with ID 3:
    $res = $resty->put(
        '/=/model/Comments/id/3',
        { title: "New title" }
    );

    # Remove the comment with the ID 3:
    $res = $resty->delete('/=/model/Comments/id/3');

DESCRIPTION

This class inherits from WWW::OpenResty, which does automatic JSON serialization for input and output data. In addition, it croaks on errors returned from the OpenResty server.

METHODS

This class exposes all the methods of its parent class, WWW:OpenResty, like login, get, post, put, and delete, as well as its own: has_view and has_model.

Unlike the methods of WWW::OpenResty returning a raw HTTP::Response object, the methods in this class always return the Perl structure directly. That is, it automatically load the JSON literals sent by the server if no error occurs; it throws an exception out otherwise.

Also, the $content parameter in the post and put methods are plain Perl data structures rather than string literals. This class will automatically serialize the data structure into JSON before sending out via the HTTP protocol.

METHODS

$bool = $resty->has_view($view_name)

Check if the view given exists.

$bool = $resty->has_model($model_name)

Check if the model given exists.

AUTHOR

agentzh <agentzh at yahoo.cn>

COPYRIGHT

Copyright (c) 2008 by Yahoo! China EEEE Works, Alibaba Inc.

License

The "MIT" License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.