diff options
Diffstat (limited to 'bin/http-console')
-rw-r--r-- | bin/http-console | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/http-console b/bin/http-console index 25aaad8..3871c36 100644 --- a/bin/http-console +++ b/bin/http-console @@ -4,7 +4,7 @@ use 5.010; use Term::ReadLine; use Getopt::Long; -use YAML::Syck; +use JSON; my $url = shift; my $format_mode = 'append'; @@ -25,6 +25,8 @@ my ($content, $result); my $term = Term::ReadLine->new("http::net::console"); my $prompt = $url . '> '; while (defined(my $in = $term->readline($prompt))) { + map { http::net::console->meta->remove_net_api_method($_) } + http::net::console->meta->get_all_api_methods(); if ($in =~ /^(GET|DELETE)\s(.*)$/) { my $http_console = http::net::console->new( api_base_url => $url, @@ -37,7 +39,7 @@ while (defined(my $in = $term->readline($prompt))) { path => $2 ); ($content, $result) = $http_console->anonymous; - say $result->content; + say JSON->new->pretty->encode($content); } elsif ($in =~ /^(POST|PUT)\s(.*)(?:\s(.*))$/) { my $method = $1; @@ -60,22 +62,29 @@ while (defined(my $in = $term->readline($prompt))) { } ); ($content, $result) = $http_console->anonymous; - say $result->content; + say pretty_output($content); } elsif ($in eq 'show headers') { if (defined $result) { - say Dump $result->headers; + map { say $_ . ": " . $result->header($_) } + keys %{$result->headers}; + say ""; } else { say "no headers to show"; } + } elsif ($in eq 'show content') { if (defined $content) { - say Dump $result->content; + say pretty_output($content); } else { say "no content to show"; } } } + +sub pretty_output { + JSON->new->pretty->encode(shift); +} |