NAME

WWW::API - Module for building clients for RESTful web service APIs

VERSION

version 0.03

SYNOPSIS

package WWW::GitHub::Repo;

use WWW::API;

with 'WWW::API::Role::Encoder::WWWFormURLEncoded';
with 'WWW::API::Role::Decoder::JSON';

define_api 'https://api.github.com';

get_api 'repo',  '/repos/:user/:repo';
get_api 'repos', '/users/:user/repos' => (
  optional => ['type']
);

1;

package main;

use WWW::GitHub::Repo;

my $gh = WWW::GitHub::Repo -> new;

my $repos = $gh -> repos(
  user => 'AlexBio',
  type => 'owner'
);

DESCRIPTION

WWW::API is a minimal framework to build clients for RESTful web service APIs.

SUBROUTINES

define_api $base_url, %opts

Define a new API client with base URL $base_url.

Available options are:

headers

A custom subroutine that returns an hashref containing HTTP headers.

get_api $name, $path, %opts

Add a new GET API method with name $name which fetches $path.

Additional available options are:

See "OPTIONS" for the additional options.

post_api $name, $path, %opts

Add a new POST API method with name $name which fetches $path.

See "OPTIONS" for the additional options.

put_api $name, $path, %opts

Add a new PUT API method with name $name which fetches $path.

See "OPTIONS" for the additional options.

delete_api $name, $path, %opts

Add a new DELETE API method with name $name which fetches $path.

See "OPTIONS" for the additional options.

patch_api $name, $path, %opts

Add a new PATCH API method with name $name which fetches $path.

See "OPTIONS" for the additional options.

OPTIONS

Additional available options are:

encoder

A custom data encoding subroutine, used to serialize data sent to the web services. By default data is encoded to www_form_urlencoded.

decoder

A custom data decoding subroutine, use to deserialize data received from the web services. By default data is decoded from JSON.

headers

A custom subroutine that returns an hashref containing additional HTTP headers.

AUTHOR

Alessandro Ghedini <alexbio@cpan.org>

LICENSE AND COPYRIGHT

Copyright 2012 Alessandro Ghedini.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.