App-Adenosine

 view release on metacpan or  search on metacpan

bin/adenosine  view on Meta::CPAN


      $ GET '/blogs/47?param=foo&otherparam=bar' -Q

To specify a query string without disabling URL encoding on the path the
C<-q> option is used, like this:

      $ GET /blogs/47 -q 'param=foo&otherparam=bar'

Finally, you can use the curl C<-d> and C<-G> options, like this:

      $ GET /blogs/47 -d 'param=foo' -d 'otherparam=bar' -G

However, if you want to pass both GET parameters in the query string B<and>
POST parameters in the request body, curl cannot support this by itself.
Using the C<-q> or C<-Q> adenosine options with the C<-d> curl option will accomplish
this, like so:

      $ POST '/blogs/47?param=foo&otherparam=bar' -Q -d 'postparam=baz'

=head1 POST/PUT Requests and Data

Normally you would probably want to provide the request body data right on
the command line like this:

      $ PUT /blogs/5.json '{"title" : "hello", "body" : "this is it"}'

But sometimes you will want to send the request body from a file instead. To
do that you pipe in the contents of the file:

      $ PUT /blogs/5.json < /tmp/t # !!!

Or you can pipe the data from another program, like this:

      $ myprog | PUT /blogs/5.json # !!!

Or, interestingly, as a filter pipeline with
C<jsawk|http://github.com/micha/jsawk>:

      $ GET /blogs/5.json | jsawk 'this.author="Bob Smith";this.tags.push("news")' | PUT

Notice how the C<path> argument is omitted from the C<PUT> command.

=head2 Edit PUT/POST Data In Vi

With the C<-V> options you can pipe data into C<PUT> or C<POST>, edit it in vi,
save the data (using C<:wq> in vi, as normal) and the resulting data is then
PUT or POSTed. This is similar to the way C<visudo> works, for example.

      $ GET /blogs/2 | PUT -V

This fetches the data and lets you edit it, and then does a PUT on the
resource. If you don't like vi you can specify your preferred editor by
setting the C<EDITOR> environment variable.

=head1 Errors and Output

For successful 2xx responses, the response body is printed on stdout. You
can pipe the output to stuff, process it, and then pipe it back to adenosine,
if you want.

For responses other than 2xx the response body is dumped to stderr.

=head1 Passing Command Line Options To Curl

Anything after the (optional) C<path> and C<data> arguments is passed on to
C<curl>.

For example:

      $ GET /blogs.json -H "Range: items=1-10"

The C<-H "Range: items=1-10"> argument will be passed to C<curl> for you. This
makes it possible to do some more complex operations when necessary.

      $ POST -v -u user:test

In this example the C<path> and C<data> arguments were left off, but C<-v> and
C<-u user:test> will be passed through to C<curl>, as you would expect.

Here are some useful options to try:

=over 2

=item C<-v>

verbose output, shows HTTP headers and status on stderr

=item C<-j>

junk session cookies (refresh cookie-based session)

=item <-u $username:$password>

HTTP basic authentication

=item <-H $header>

add request header (this option can be added more than once)

=back

=head2 Setting The Default Curl Options

Sometimes you want to send some options to curl for every request. It
would be tedious to have to repeat these options constantly. To tell
adenosine to always add certain curl options you can specify those options
when you call adenosine to set the URI base. For example:

      $ adenosine example.com:8080 -H "Accept: application/json" -u user:pass

Every subsequent request will have the C<-H "Accept:..."> and C<-u user:...>
options automatically added. Each time adenosine is called this option list
is reset.

=head2 Per-Host/Per-Method Curl Configuration Files

Adenosine supports a per-host/per-method configuration file to help you with
frequently used curl options. Each host (including the port) can have its
own configuration file in the F<~/.resty> directory. The file format is

      $ GET [arg] [arg] ...
      $ PUT [arg] [arg] ...
      $ POST [arg] [arg] ...
      $ DELETE [arg] [arg] ...

Where the C<arg>s are curl command line arguments. Each line can specify
arguments for that HTTP verb only, and all lines are optional.

So, suppose you find yourself using the same curl options over and over. You
can save them in a file and adenosine will pass them to curl for you. Say this
is a frequent pattern for you:

      $ adenosine localhost:8080
      $ GET /Blah -H "Accept: application/json"
      $ GET /Other -H "Accept: application/json"
      ...
      $ POST /Something -H "Content-Type: text/plain" -u user:pass
      $ POST /SomethingElse -H "Content-Type: text/plain" -u user:pass
      ...

It's annoying to add the C<-H> and C<-u> options to curl all the time. So
create a file F<~/.resty/localhost:8080>, like this:

F<~/.resty/localhost:8080>

      GET -H "Accept: application/json"



( run in 2.081 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )