HTTP::Request::JSON - a subclass of HTTP::Request that understands JSON
my $request = HTTP::Request::JSON->new(PATCH => "$base_url/death_ray");
# $request has an Accept header saying it's OK to send JSON back
self_destruct_mechanism => 'disabled',
users_allowed_to_override => ,
# Request content is JSON-encoded, and the content-type is set.
This is a simple subclass of HTTP::Request::JSON that does two things. First of all, it sets the Accept header to application/json as soon as it's created. Secondly, it implements a "json_content" method that adds the supplied data structure to the request, as JSON, or returns the current JSON contents as a Perl structure.
As HTTP::Request->new, but also sets the Accept header.
In: $perl_data (optional)
A mutator for the request's JSON contents.
As a setter, supplied with a valid JSON data structure, sets the request contents to be the JSON-encoded version of that data structure, and sets the Content-Type header to application/json. Will throw an exception if the data structure cannot be converted to JSON. Returns the resulting string contents.
All strings in $perl_data must be Unicode strings, or you will get encoding errors.
As a getter, decodes the request contents from JSON into a Perl structure, and returns the resulting data structure.
Returns an object that knows how to handle the encode and decode methods. By default whatever LWP::JSON::Tiny->json_object returns. This is what you'd subclass if you wanted to use some other kind of JSON object instead.
Sam Kington <email@example.com>
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 (c) 2015 Sam Kington.
This library is free software and may be distributed under the same terms as perl itself.
To install LWP::JSON::Tiny, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.