My first Mojolicious Plugin - Proxy

2010-12-16 − 🏷 http 🏷 mojolicious 🏷 perl

A few days ago I uploaded my first Mojolicious plugin to CPAN, Mojolicious::Plugin::Proxy. My use case was that I am writing a simple single-file html5/javascript app, which needed to access a remote JSON feed. When running on a device with file:/// URLs, cross-site scripting is not an issue, but when running on a web-server, my app is unable to reach that remote JSON feed, so I wrote this plugin to allow me to simply proxy JSON requests from the local server to the remote one. This is how it works

    plugin 'proxy';
   get 'ws' => sub { shift->proxy_to('http://remote_url', with_query_params=>1);

The fact that Mojolicious includes a full async http client made this plugin trivial to implement. The unit tests is almost more code than the module itself.