POE::Component::Client::REST::JSON - Low-level interface for JSON REST calls


POE-Component-Client-CouchDB documentation Contained in the POE-Component-Client-CouchDB distribution.

Index


Code Index:

NAME

Top

POE::Component::Client::REST::JSON - Low-level interface for JSON REST calls

VERSION

Top

Version 0.05

SYNOPSIS

Top

This is just a thin specialization of POE::Component::Client::REST that does some JSON encoding and decoding - see the methods for details.

METHODS

Top

cook_request

All requests get their content encoded into JSON and some appropriate headers set.

cook_response

Responses are deserialized from JSON, and callbacks receive two arguments: the deserialized structure and the HTTP::Response object.

AUTHOR

Top

Paul Driver, <frodwith at cpan.org>

BUGS

Top

Probably.

COPYRIGHT & LICENSE

Top


POE-Component-Client-CouchDB documentation Contained in the POE-Component-Client-CouchDB distribution.

package POE::Component::Client::REST::JSON;
use JSON;
use Moose;

our $VERSION = '0.05';

extends q(POE::Component::Client::REST);

sub cook_request {
  my $request = $_[0];
  if(my $content = $request->content) {
    $content = encode_json($content);
    $request->content_type('application/json');
    $request->content($content);
    $request->header('Content-Encoding' => 'UTF-8');
  };
  return $request;
};
has '+request_cooker' => (default => sub { \&cook_request });

sub cook_response {
  my $response = $_[0];
  return (decode_json($response->content), $response);
};
has '+response_cooker' => (default => sub { \&cook_response });

1;

__END__