View on
MetaCPAN
Joe Papperello > WWW-JSON-1.02 > WWW::JSON::Response

Download:
WWW-JSON-1.02.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source  

NAME ^

WWW::JSON::Response - Response objects returned by WWW::JSON requests

SYNOPSIS ^

    use WWW::JSON;

    my $wj = WWW::JSON->new(
        base_url => 'http://api.metacpan.org/v0?fields=name,distribution&size=1',
        post_body_format           => 'JSON',
        default_response_transform => sub { shift->{hits}{hits}[0]{fields} },
    );

    my $get = $wj->get(
        '/release/_search',
        {
            q      => 'author:ANTIPASTA',
            filter => 'status:latest',
        }
    );

    if ($get->success) {
        say $r->res->{distribution};
    } else {
        say $r->error;
    }

DESCRIPTION ^

WWW::JSON::Response objects return data from WWW::JSON requests.

PARAMETERS ^

http_response

An HTTP::Response object containing json

METHODS ^

success

True if both the http request returned successfully (HTTP 200 OK) AND the json was successfully decoded. False if either of those things went horribly wrong.

error If the http request failed then this is the contents of HTTP::Response->status_line. If the json parse failed it is a combination of the error encountered during JSON parse and the http status line

response

The results of decoding the json response. Will be decoded even in the event of an error, since hopefully the API is nice enough to return some json describing the error that occurred.

res

Alias for response

code

HTTP code returned by this request

status_line

HTTP status_line code returned by this request

content

The HTTP response's non json-decoded content

url

The url of this request

http_response

The HTTP::Response object corresponding to the request

LICENSE ^

Copyright (C) Joe Papperello.

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

AUTHOR ^

Joe Papperello <antipasta@cpan.org>

syntax highlighting: