App-Adenosine
view release on metacpan or search on metacpan
bin/adenosine view on Meta::CPAN
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"
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
$ GET /Other
...
$ POST /Something
$ POST /SomethingElse
...
Sweet! Much better.
=head1 Exit Status
Successful requests (HTTP respose with 2xx status) return zero.
Otherwise, the first digit of the response status is returned (i.e., 1 for
1xx, 3 for 3xx, 4 for 4xx, etc.) This is because the exit status is an 8 bit
integer---it can't be greater than 255. If you want the exact status code
you can always just pass the C<-v> option to curl.
=head1 Using Adenosine In Shell Scripts C<!!!>
Since adenosine creates the REST verb functions in the shell, when
using it from a script you must C<source> it before you use any of the
functions. However, it's likely that you don't want it to be overwriting the
adenosine host history file, and you will almost always want to set the URI
base explicitly.
#!/usr/bin/env bash
# Load adenosine, don't write to the history file, and set the URI base
. /path/to/adenosine-exports -W 'https://myhost.com/data*.json'
# GET the JSON list of users, set each of their 'disabled' properties
# to 'false', and PUT the modified JSON back
GET /users | jsawk 'this.disabled = false' | PUT
Here the C<-W> option was used when loading the script to prevent writing
to the history file and an initial URI base was set at the same time. Then a
JSON file was fetched, edited using L<jsawk|http://github.com/micha/jsawk>,
and re-uploaded to the server.
=head1 Application Configuration
Adenosine may be configured by placing a C<YAML> document in
F<~/.adenosinerc.yml>. More parts of adenosine will be configurable as time
goes on, but right now the only real configuration is for plugins.
Adenosine's plugin architecture (documented at
L<App::Adenosine/USING PLUGINS> and L<App::Adenosine/CREATING PLUGINS>) can be
used to color code headers, time the request, or more, if you choose to write
more plugins. Enabling a plugin is simple with the F<~/.adenosinerc.yml>
file. Here is how you would enable both L<App::Adenosine::Plugin::Stopwatch>
and L<App::Adenosine::Plugin::Rainbow>, including a little bit of extra
(non-required) configuration to customize some colors for C<::Rainbow>.
plugins:
- ::Stopwatch
- ::Rainbow: {
request_method_color: cyan
}
The following would work if you didn't want to configure C<::Rainbow>
plugins:
- ::Stopwatch
- ::Rainbow
Another option allows the user to disable the XDG based directory structure
(typically F<~/.config>). Simply put the following in your
F<~/.adenosinerc.yml>:
enable_xdg: 0
=head1 Working With JSON or XML Data
JSON REST web services require some special tools to make them accessible
and easily manipulated in the shell environment. The following are a few
scripts that make dealing with JSON data easier.
=over 2
=item
L<Jsawk|http://github.com/micha/jsawk> can be used to process and filter JSON
data from and to adenosine, in a shell pipeline. This takes care of parsing
the input JSON correctly, rather than using regexes and sed, awk, perl or
the like, and prints the resulting output in correct JSON format, as well.
GET /blogs.json |jsawk -n 'out(this.title)' # prints all the blog titles
=item
The included C<pp> script will pretty-print JSON for you.
GET /blogs.json |pp # pretty-prints the JSON output from adenosine
=item
Another way to format JSON output:
( run in 1.940 second using v1.01-cache-2.11-cpan-b16cb0d3907 )