in reply to Re: Building a URL Query String from a Data Structure
in thread Building a URL Query String from a Data Structure

Thank you taking the time to help out a poor lost soul.

I got it installed and working just before I left work yesterday. (CPAN got stuck in a seemingly infinite loop working out dependencies, so I just started installing the dependencies until CPAN could get HTTP::Request::JSON installed.)

This code:

#!/usr/bin/perl use strict; use warnings; use feature("say"); use Data::Dumper::Simple; use HTTP::Request::JSON; my $perl_structure = { 'sub' => { 'name' => 'foo', 'message' => 'bar' }, 'name' => 'test name', 'file_ids' => [ 1, 2 ] }; my $request = HTTP::Request::JSON->new; $request->json_content($perl_structure); say $request->decoded_content; say Dumper $request;

results in this output:

{"file_ids":[1,2],"name":"test name","sub":{"message":"bar","name":"fo +o"}} $request = bless( { '_content' => '{"file_ids":[1,2],"name":"test name +","sub":{"message":"bar","name":"foo"}}', '_uri' => undef, '_headers' => bless( { 'content-type' => 'applicat +ion/json', 'accept' => 'application/js +on' }, 'HTTP::Headers' ), '_method' => undef }, 'HTTP::Request::JSON' );

So it looks like HTTP::Request::JSON creates an HTTP::Request object set up for a POST that contains a JSON payload.

That gets me two thirds the way there, but I'm missing the CGI query string. I'm working with a RESTful web API. I need to send a GET and the API only accepts the query string. It ignores any content body that is sent. Actually, that's why I'm doing this. The API used to work fine with JSON sent as an attachment, then somebody got all standards compliant (or something) and now their GET requests only work with query strings passing data.



-- Yeah, I'm a Delt.