#!/usr/bin/perl

=pod

DEPS:
* Make sure to install JSON::XS and YAML::XS, probably with cpan.

NOTE:
* for each arg of type URL http request get a application/json
* convert the json to yaml and print out

=cut

use LWP::UserAgent;
use JSON::XS;
use YAML::XS;

my $ua = LWP::UserAgent->new;

foreach my $arg (@ARGV) {
    # print $arg, "\n";
    my $server_endpoint = $arg;
    my $req = HTTP::Request->new(GET => $server_endpoint);
    $req->header('content-type' => 'application/json');

    my $resp = $ua->request($req);
    if ($resp->is_success) {    
        {
            local $YAML::XS::Boolean = "JSON::PP";
            print Dump (JSON::XS->new->utf8->decode ($resp->decoded_content));
        }
    }
    else {
        print "HTTP GET error code: ", $resp->code, "\n";
        print "HTTP GET error message: ", $resp->message, "\n";
    }
}
