LWP::UserAgent::JSON

- NAME
- SYNOPSIS
- DESCRIPTION
  - post_json
    - put_json
    - patch_json
    - patch
  - simple_request
  - rebless_maybe
- AUTHOR
- COPYRIGHT
- LICENSE

# NAME

LWP::UserAgent::JSON - a subclass of LWP::UserAgent that understands JSON

# SYNOPSIS

     my $user_agent = LWP::UserAgent::JSON->new;
     my $request    = HTTP::Request::JSON->new(...);
     my $response   = $user_agent->request($request);
     # $response->isa('HTTP::Response::JSON') if we got back JSON

# DESCRIPTION

This is a subclass of LWP::UserAgent which recognises if it gets JSON output back, and if so returns an HTTP::Response::JSON object instead of a HTTP::Response object. It exposes the logic of reblessing the HTTP::Response object in case you get handed a HTTP::Response object by some other method.

It also offers a handful of convenience methods to directly convert parameters into JSON for POST, PUT and PATCH requests.

## post_json

Like LWP::UserAgent::post, except for when it's called as `post_json($url, $form_ref, ...)`, in which case $form_ref is turned into JSON. Obviously if you specify Content-Type or Content in subsequent header arguments they'll take precedence.

### put_json

A variant on LWP::UserAgent::put with the same transformations as post_json. This requires that your version of LWP supports PUT, i.e. you have LWP 6.00 or later.

### patch_json

As post_json and put_json, but generates a PATCH request instead. As put_json, you need a semi-modern version of LWP for this.

### patch

LWP::UserAgent doesn't actually implement a patch method, so it's defined here.

## simple_request

As LWP::UserAgent::simple_request, but returns a HTTP::Response:JSON object instead of a HTTP::Response object if the response is JSON.

## rebless_maybe

     In: $object
     Out: $reblessed

Supplied with a HTTP::Request or HTTP::Response object, looks to see if it's a JSON object, and if so reblesses it to be a HTTP::Request::JSON or HTTP::Response::JSON object respectively. Returns whether it reblessed the object or not.

# AUTHOR

Sam Kington <skington@cpan.org>

The source code for this module is hosted on GitHub https://github.com/skington/lwp-json-tiny - this is probably the best place to look for suggestions and feedback.

# COPYRIGHT

Copyright (c) 2015 Sam Kington.

# LICENSE

This library is free software and may be distributed under the same terms as perl itself.