Introducing Sub::Spec::HTTP::Server: Perl functions over HTTP, the dead easy way

Below is one way to serve function call requests (e.g. providing API service) using just one line.

Modules hitting CPAN mirrors as we speak (metacpan link: Sub::Spec::HTTP::Server):

# example module to export to HTTP, provides sprintfn()
$ cpanm Text::sprintfn

# module to do the magic, provides 'servepm'
$ cpanm Sub::Spec::HTTP::Server

$ servepm Text::sprintfn

$ wget -O- -q 'http://localhost:5000/api/Text::sprintfn?args:j=["Agent %(num)03d",{"num":7}]'
[200,"OK","Agent 007"]


  • Plack/PSGI-based
  • Support HTTPS natively, as well as Unix sockets (using Gepok PSGI server)
  • by default support JSON/YAML/PHP/text input/output (support complex arguments instead of just scalars)
  • more than just function call: usage, spec, list modules, list subroutines
  • propagates Log::Any log messages from server
  • use middleware to add authentication, authorization, etc.
  • support proxying

I also wrote Sub::Spec::Use, to easily use a remote module:

use Sub::Spec::Use "http://localhost:5000/api/Text::sprintfn" => qw(:all);
printfn "%(num)03d\n", {num=>7};

1 Comment

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays).