App-Adenosine
view release on metacpan or search on metacpan
Or you can pipe the data from another program, like this:
$ myprog | PUT /blogs/5.json # !!!
Or, interestingly, as a filter pipeline with
jsawk|http://github.com/micha/jsawk:
$ GET /blogs/5.json | jsawk 'this.author="Bob Smith";this.tags.push("news")' | PUT
Notice how the path argument is omitted from the PUT command.
Edit PUT/POST Data In Vi
With the -V options you can pipe data into PUT or POST, edit it in vi,
save the data (using :wq in vi, as normal) and the resulting data is
then PUT or POSTed. This is similar to the way 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 EDITOR environment variable.
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.
Passing Command Line Options To Curl
Anything after the (optional) path and data arguments is passed on to
curl.
For example:
$ GET /blogs.json -H "Range: items=1-10"
The -H "Range: items=1-10" argument will be passed to curl for you.
This makes it possible to do some more complex operations when
necessary.
$ POST -v -u user:test
In this example the path and data arguments were left off, but -v and
-u user:test will be passed through to curl, as you would expect.
Here are some useful options to try:
-v
verbose output, shows HTTP headers and status on stderr
-j
junk session cookies (refresh cookie-based session)
<-u $username:$password>
HTTP basic authentication
<-H $header>
add request header (this option can be added more than once)
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 -H "Accept:..." and -u user:...
options automatically added. Each time adenosine is called this option
list is reset.
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 ~/.resty directory. The file
format is
$ GET [arg] [arg] ...
$ PUT [arg] [arg] ...
$ POST [arg] [arg] ...
$ DELETE [arg] [arg] ...
Where the args 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 -H and -u options to curl all the time. So
create a file ~/.resty/localhost:8080, like this:
~/.resty/localhost:8080
GET -H "Accept: application/json"
POST -H "Content-Type: text/plain" -u user:pass
Then any GET or POST requests to localhost:8080 will have the specified
options prepended to the curl command line arguments, saving you from
having to type them out each time, like this:
$ GET /Blah
( run in 1.704 second using v1.01-cache-2.11-cpan-2398b32b56e )