App-Presto
view release on metacpan or search on metacpan
- "deserialize" HTML to text when printing to STDOUT
- fix broken "form" command
- add "scripts" command to list scripts available for sourcing
- add support for silent commands in scripts (command is not "echo'd" to STDOUT before executing)
0.004 2012-09-24 11:41:02 America/Chicago
- fixed bug with setting the "deserialize_response" config
0.003 2012-09-20 16:26:47 America/Chicago
- better tab completion options for various commands
- warn on missing content-type header for request
- stricter config handling (only certain keys are allowed)
- added support for $(PROMPT[hullo?]) expansion
- added Changes file
0.002 Tue Sep 18 08:12:48 CDT 2012
- added required version for File::Path
0.001 Fri Sep 07 2012
- the first release
foo=bar&baz=1%2C2%2C3
Response Handling
By default, presto will just dump the response body to the screen after
a request is completed. There are additional options, however:
# dump full request/response to the screen (exactly as transmitted over the wire)
http://my-server.com> config verbose 1
# parse the response according to the content-type and use
# Data::Dumper to display it
http://my-server.com> config deserialize_response 1
# use something other than Data::Dumper to dump a parsed
# response body
http://my-server.com> config pretty_printer JSON
http://my-server.com> config pretty_printer Data::Dump
# send the output to a file (the '>' must not be followed by any white-space!)
http://my-server.com> GET /some-image.png >some-image.png
Pretty-printing can be especially helpful for making XML or JSON
response bodies more human-readable.
When deserialize_response is set, if the content-type of the response
is "text/html", the HTML is automatically stripped with
HTML::FormatText::WithLinks and displayed as formatted text.
If the request or response body is binary (using a simple heuristic
like the -B file-test operator), the output is not printed to STDOUT.
Instead, you may want to use output redirection as show above and send
the response body to a file.
http://my-server.com> GET /some-image.jpg >foo.jpg
specify that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
TODO: Allow data structure references (from STASH or even BODY) to be
passed to a POST or PUT command which is then serialized based on the
content-type of the request before being sent over the wire.
(EXPERIMENTAL) Data::DPath integration
As an add-on to the variable interpolated described above, you can use
dpath expressions to further process the data returned from the REST
service. Another very contrived example:
http://my-server.com> GET /products.json
[{"id":"1","name":"My Product"},{"id":"2","name":"Another Product"}]
README.mkdn view on Meta::CPAN
foo=bar&baz=1%2C2%2C3
## Response Handling
By default, presto will just dump the response body to the screen after
a request is completed. There are additional options, however:
# dump full request/response to the screen (exactly as transmitted over the wire)
http://my-server.com> config verbose 1
# parse the response according to the content-type and use
# Data::Dumper to display it
http://my-server.com> config deserialize_response 1
# use something other than Data::Dumper to dump a parsed
# response body
http://my-server.com> config pretty_printer JSON
http://my-server.com> config pretty_printer Data::Dump
# send the output to a file (the '>' must not be followed by any white-space!)
http://my-server.com> GET /some-image.png >some-image.png
Pretty-printing can be especially helpful for making XML or JSON response
bodies more human-readable.
When `deserialize_response` is set, if the content-type of the
response is "text/html", the HTML is automatically stripped with
[HTML::FormatText::WithLinks](https://metacpan.org/pod/HTML::FormatText::WithLinks) and displayed as formatted text.
If the request or response body is binary (using a simple heuristic
like the `-B` file-test operator), the output is not printed to STDOUT.
Instead, you may want to use output redirection as show above and send
the response body to a file.
http://my-server.com> GET /some-image.jpg >foo.jpg
README.mkdn view on Meta::CPAN
that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
**TODO:** Allow data structure references (from `STASH` or even `BODY`)
to be passed to a POST or PUT command which is then serialized based
on the content-type of the request before being sent over the wire.
## (EXPERIMENTAL) Data::DPath integration
As an add-on to the variable interpolated described above, you can
use dpath expressions to further process the data returned from the
REST service. Another very contrived example:
http://my-server.com> GET /products.json
[{"id":"1","name":"My Product"},{"id":"2","name":"Another Product"}]
foo=bar&baz=1%2C2%2C3
=head2 Response Handling
By default, presto will just dump the response body to the screen after
a request is completed. There are additional options, however:
# dump full request/response to the screen (exactly as transmitted over the wire)
http://my-server.com> config verbose 1
# parse the response according to the content-type and use
# Data::Dumper to display it
http://my-server.com> config deserialize_response 1
# use something other than Data::Dumper to dump a parsed
# response body
http://my-server.com> config pretty_printer JSON
http://my-server.com> config pretty_printer Data::Dump
# send the output to a file (the '>' must not be followed by any white-space!)
http://my-server.com> GET /some-image.png >some-image.png
Pretty-printing can be especially helpful for making XML or JSON response
bodies more human-readable.
When C<deserialize_response> is set, if the content-type of the
response is "text/html", the HTML is automatically stripped with
L<HTML::FormatText::WithLinks> and displayed as formatted text.
If the request or response body is binary (using a simple heuristic
like the C<-B> file-test operator), the output is not printed to STDOUT.
Instead, you may want to use output redirection as show above and send
the response body to a file.
http://my-server.com> GET /some-image.jpg >foo.jpg
that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
B<TODO:> Allow data structure references (from C<STASH> or even C<BODY>)
to be passed to a POST or PUT command which is then serialized based
on the content-type of the request before being sent over the wire.
=head2 (EXPERIMENTAL) Data::DPath integration
As an add-on to the variable interpolated described above, you can
use dpath expressions to further process the data returned from the
REST service. Another very contrived example:
http://my-server.com> GET /products.json
[{"id":"1","name":"My Product"},{"id":"2","name":"Another Product"}]
lib/App/Presto/Client.pm view on Meta::CPAN
sub clear_headers {
my $self = shift;
%{$self->_rest_client->{_headers} || {}} = ();
return;
}
sub GET {
my $self = shift;
my $uri = $self->_make_uri(@_);
my $existing_content_type = $self->clear_header('content-type'); # GET shouldn't have a content type
my $response = $self->_rest_client->GET($uri);
$self->set_header('content-type', $existing_content_type) if $existing_content_type;
return $response;
}
sub HEAD {
my $self = shift;
my $uri = $self->_make_uri(@_);
my $existing_content_type = $self->clear_header('content-type'); # HEAD shouldn't have a content type
my $response = $self->_rest_client->HEAD($uri);
$self->set_header('content-type', $existing_content_type) if $existing_content_type;
return $response;
}
sub DELETE {
my $self = shift;
my $uri = $self->_make_uri(shift);
my $response = $self->_rest_client->request('DELETE',$uri, shift);
return $response;
}
lib/App/Presto/Command/HTTP.pm view on Meta::CPAN
);
}
sub _mk_proc_for {
my $self = shift;
my $method = shift;
my $client = $self->client;
return sub {
add_url($method => $_[0]);
if($method =~ m/^P/){
warn " * no content-type header currently set\n" unless $client->get_header('Content-Type');
}
my $out;
if(($out) = $_[-1] =~ /^>(.+)/){
pop @_;
}
$client->$method(@_);
$self->handle_response($client, $out);
}
}
lib/App/Presto/Command/headers.pm view on Meta::CPAN
);
} elsif( my $auth = $client->get_header('Authorization') ){
$auth =~ s/Basic //;
my ($u,$p) = split(/:/, MIME::Base64::decode( $auth ), 2 );
print "Username: $u\nPassword: $p\n";
}
},
},
type => {
minargs => 1,
desc => 'Set content-type header',
args => sub { ['application/json','application/x-www-form-urlencoded'] },
proc => sub { $client->set_header( 'Content-Type', shift ) },
},
headers => {
maxargs => 0,
alias => 'header',
},
header => {
desc => 'get/set/list/clear HTTP headers',
args => [sub {my %headers = $client->all_headers; return ['--unset','--clear', keys %headers]} ],
( run in 2.817 seconds using v1.01-cache-2.11-cpan-524268b4103 )