App-Presto
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
opposite end of the spectrum) just using curl directly on the
command-line. This tool attempts to find some sort of middle ground by
providing a quasi-DSL for interacting with a RESTful service in an
interactive way.
FEATURES
Basic HTTP methods
All HTTP methods are implemented as commands in presto. The URL that is
given is appended to the endpoint specified when presto is invoked as
shown in the SYNOPSIS above.
Request Building
If the endpoint contains a * character the URL fragment specified in
the GET/POST/etc command is inserted at that point. This allows you to
do things like auto-append a file extension to all URLs. For instance:
bash$ presto http://my-server.com*.json
http://my-server.com> GET /product/1
In this case, the full URL would be
http://my-server.com/product/1.json. If no * is found in the URL, the
URL fragment is simply appended at the end of the endpoint.
All arguments after the first will be treated as query parameters (for
GET/HEAD/DELETE requests) or request content (for POST/PUT requests).
For instance:
http://my-server.com> GET /products limit=10 offset=20
# request goes to http://my-sever.com/products?limit=10&offset=20
http://my-server.com> POST /products '{"name":"A New Product"}'
# request goes to http://my-sever.com/products with the body as specified
README.mkdn view on Meta::CPAN
answers typically point to some horrible GUI or (on the complete opposite
end of the spectrum) just using `curl` directly on the command-line.
This tool attempts to find some sort of middle ground by providing a
quasi-DSL for interacting with a RESTful service in an interactive way.
# FEATURES
## Basic HTTP methods
All HTTP methods are implemented as commands in presto. The URL that is
given is appended to the endpoint specified when presto is invoked as
shown in the SYNOPSIS above.
## Request Building
If the endpoint contains a `*` character the URL fragment specified in
the GET/POST/etc command is inserted at that point. This allows you to
do things like auto-append a file extension to all URLs. For instance:
bash$ presto http://my-server.com*.json
http://my-server.com> GET /product/1
In this case, the full URL would be
`http://my-server.com/product/1.json`. If no `*` is found in the URL,
the URL fragment is simply appended at the end of the endpoint.
All arguments after the first will be treated as query parameters (for
GET/HEAD/DELETE requests) or request content (for POST/PUT requests). For
instance:
http://my-server.com> GET /products limit=10 offset=20
# request goes to http://my-sever.com/products?limit=10&offset=20
http://my-server.com> POST /products '{"name":"A New Product"}'
# request goes to http://my-sever.com/products with the body as specified
answers typically point to some horrible GUI or (on the complete opposite
end of the spectrum) just using C<curl> directly on the command-line.
This tool attempts to find some sort of middle ground by providing a
quasi-DSL for interacting with a RESTful service in an interactive way.
=head1 FEATURES
=head2 Basic HTTP methods
All HTTP methods are implemented as commands in presto. The URL that is
given is appended to the endpoint specified when presto is invoked as
shown in the SYNOPSIS above.
=head2 Request Building
If the endpoint contains a C<*> character the URL fragment specified in
the GET/POST/etc command is inserted at that point. This allows you to
do things like auto-append a file extension to all URLs. For instance:
bash$ presto http://my-server.com*.json
http://my-server.com> GET /product/1
In this case, the full URL would be
C<http://my-server.com/product/1.json>. If no C<*> is found in the URL,
the URL fragment is simply appended at the end of the endpoint.
All arguments after the first will be treated as query parameters (for
GET/HEAD/DELETE requests) or request content (for POST/PUT requests). For
instance:
http://my-server.com> GET /products limit=10 offset=20
# request goes to http://my-sever.com/products?limit=10&offset=20
http://my-server.com> POST /products '{"name":"A New Product"}'
# request goes to http://my-sever.com/products with the body as specified
lib/App/Presto.pm view on Meta::CPAN
is => 'lazy',
);
sub _build_client {
my $self = shift;
return App::Presto::Client->new(config => $self->config);
}
has config => (
is => 'rw',
handles => ['endpoint'],
);
has _stash => (
is => 'lazy',
handles => ['stash'],
);
sub _build__stash {
my $self = shift;
return App::Presto::Stash->new;
lib/App/Presto/Client.pm view on Meta::CPAN
my $uri = $self->_make_uri(shift);
$self->_rest_client->PUT( $uri, shift );
}
sub _make_uri {
my $self = shift;
my $local_uri = shift;
my @args = @_;
my $config = $self->config;
my $endpoint;
$local_uri = '/' if ! defined $local_uri;
$local_uri = URI->new($local_uri);
if ( $local_uri->scheme ) {
$endpoint = $local_uri;
} else {
my $local_path = $local_uri->path;
$endpoint = $config->endpoint;
$endpoint .= '*' unless $endpoint =~ m/\*/;
$endpoint =~ s{\*}{$local_path};
$endpoint .= '?' . $local_uri->query if $local_uri->query;
}
my $u = $self->_append_query_params( $endpoint, @args );
return "$u";
}
sub _append_query_params {
my $self = shift;
my $u = URI->new(shift);
my @args = @_;
foreach my $next (@args) {
$u->query_param_append( split( /=/, $next, 2 ) );
}
lib/App/Presto/Config.pm view on Meta::CPAN
package App::Presto::Config;
our $AUTHORITY = 'cpan:MPERRY';
$App::Presto::Config::VERSION = '0.010';
# ABSTRACT: Manage configuration for a given endpoint
use Moo;
use JSON qw(decode_json encode_json);
use File::HomeDir;
use File::Path 2.08 qw(make_path);
has endpoint => (
is => 'rw',
required => 1,
trigger => sub { delete shift->{endpoint_dir} }
);
has config => (
is => 'lazy',
clearer => 'reload',
isa => sub { die "not a HashRef" if ref($_[0]) ne 'HASH'; },
);
sub _build_config {
my $self = shift;
my $config_file = $self->file('config.json');
if (! -e $config_file ) {
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.244 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )