NAME

WWW::REST - Base class for REST resources

VERSION

version 0.023

SYNOPSIS

use XML::RSS;
use WWW::REST;
$url = WWW::REST->new("http://nntp.x.perl.org/rss/perl.par.rdf");
$url->dispatch( sub {
    my $self = shift;
    die $self->status_line if $self->is_error;
    my $rss = XML::RSS->new;
    $rss->parse($self->content);
    return $rss;
});
$url->get( last_n => 10 )->save("par.rdf");
$url->url("perl.perl5.porters.rdf")->get->save("p5p.rdf");
warn $url->dir->as_string;    # "http://nntp.x.perl.org/rss/"
warn $url->parent->as_string; # "http://nntp.x.perl.org/"
$url->delete;                 # dies with "405 Method Not Allowed"

DESCRIPTION

This module is a mixin of URI, LWP::UserAgent, HTTP::Response and a user-defined dispatch module. It is currently just a proof of concept for a resource-oriented API framework, also known as REST (Representational State Transfer).

METHODS

WWW::REST->new($string, @args)

Constructor (class method). Takes a URL string, returns a WWW::REST object. The optional arguments are passed to LWP::UserAgent->new.

$url->url($string)

Constructor (instance method). Takes a URL string, which may be relative to the object's URL. Returns a WWW::REST object, which inherits the same ua (= user-agent) and dispatcher.

$url->dispatch($coderef)

Gets or sets the dispatch code reference.

$url->_uri($uri), $url->_ua($uri), $url->_res($uri)

Gets or sets the embedded URI, LWP::UserAgent and HTTP::Response objects respectively. Note that $url can automatically delegate method calls to embedded objects, so normally you won't need to call those methods explicitly.

$url->get(%args), $url->post(%args), $url->head(%args), $url->put(%args), $url->delete(%args), $url->options(%args), $url->trace(%args), $url->connect(%args)

Performs the corresponding operation on the object; returns the object itself. If dispatch is set to a code reference, the object is passed to it instead, and returns its return value.

$url->parent()

Returns a WWW::REST object with the URL of the current object's parent directory.

$url->dir()

Returns a WWW::REST object with the URL of the current object's current directory.

Methods derived from URI

clone scheme opaque path fragment as_string canonical eq
abs rel authority path path_query path_segments query query_form
query_keywords userinfo host port host_port default_port

Methods derived from LWP::UserAgent

request send_request prepare_request simple_request request
protocols_allowed protocols_allowed protocols_forbidden
protocols_forbidden is_protocol_supported requests_redirectable
requests_redirectable redirect_ok credentials get_basic_credentials
agent from timeout cookie_jar conn_cache parse_head max_size
clone mirror proxy no_proxy

Methods derived from HTTP::Response

code message request previous status_line base is_info
is_success is_redirect is_error error_as_HTML current_age
freshness_lifetime is_fresh fresh_until

NOTES

This module is considered highly experimental and essentially unmaintained; it's kept on CPAN for historical reasons.

SEE ALSO

URI, LWP::UserAgent, HTTP::Response

AUTHORS

Audrey Tang <cpan@audreyt.org>

Shlomi Fish, http://www.shlomifish.org/ .

CC0 1.0 Universal

To the extent possible under law, 唐鳳 has waived all copyright and related or neighboring rights to WWW::REST.

This work is published from Taiwan.

http://creativecommons.org/publicdomain/zero/1.0

SUPPORT

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-www-rest at rt.cpan.org, or through the web interface at https://rt.cpan.org/Public/Bug/Report.html?Queue=WWW-REST. You will be automatically notified of any progress on the request by the system.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/shlomif/perl-WWW-REST

git clone https://github.com/shlomif/perl-WWW-REST.git

AUTHOR

Shlomi Fish <shlomif@cpan.org>

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/shlomif/perl-WWW-REST/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

COPYRIGHT AND LICENSE

Audrey Tang has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.

Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.