View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
perlancar > Perinci-Access > Perinci::Access::Manual::Examples


Annotate this POD


View/Report Bugs


Perinci::Access::Manual::Examples - Collection of examples


This document describes version 0.45 of Perinci::Access::Manual::Examples (from Perl distribution Perinci-Access), released on 2017-07-10.


(Client) Simplest usage

(Client) Meta action

(Client) List action

(Client) (HTTP)

(Client) (Pipe)

(Client) (Socket)

(Client) (Server) Dealing with binary data

The choice as JSON as the network transport protocol (because it is the lowest common denominator across languages like JavaScript, PHP, Python, Ruby, Perl) makes dealing with binary data requires an extra step or two. The Riap client libraries are equipped with some features to make this simpler and more convenient.

First, to make a function that accepts binary data (in its arguments), you need to specify the argument type as buf. To return binary data as result, you need to specify result's schema type as buf. Example:

 package MyLib;
 our %SPEC;
 $SPEC{gzip} = {
     v => 1.1,
     summary => 'Gzip some data',
     args => {
         data => {
             summary => 'Data to compress',
             schema => 'buf*',
             req => 1,
 sub gzip {
     require IO::Compress::Gzip;

     my %args = @_;
     my $compressed;
     IO::Compress::Gzip::gzip($args{data} => $compressed)
         or return [500, "Compression failed"];
     [200, "OK", $compressed];

If you use this function via Riap in-process, there's nothing to worry about since there is no round-trip to JSON. You can just:

 my $res = Perinci::Access->new->request(call => "/MyLib/gzip",
                                         {args=>{data=>"some data"}});

If you are using this function over HTTP or oher network protocol where JSON is involved, you will need to encode the argument:

 use MIME::Base64;
 my $res = Perinci::Access->new(riap_version=>1.2)->
               request(call => "http://localhost:5000/api/MyLib/gzip",
                       {args=>{"data:base64"=>encode_base64("some data","")}});

Note that you also need to specify Riap version 1.2, as this is the first version that specifies argument encoding. Also note that the result returned by the server is actually base64-encoded to be safe to pass through JSON, e.g.:

 [200, "OK", "base64 data...", {"riap.v"=>1.2, "riap.result_encoding"=>"base64"}]

But the Riap client library decodes this automatically for you, so you don't have to see it.

(Client) Debugging

(Server) (HTTP)

(Server) (Pipe)

(Server) Debugging


Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.




perlancar <>


This software is copyright (c) 2017, 2015, 2014, 2013, 2012 by

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: