Author image Mirko Westermeier


Mojolicious::Plugin::Subdispatch - create requests to your Mojolicious actions


    plugin 'Subdispatch';

    [web app stuff...]

    my $html = app->subdispatch->get('route_name', foo => 'bar')->body;


This Mojolicious plugin creates a `subdispatch` helper, which helps you creating a request for your actions, and returns the response object with your fully rendered HTML content.

The interface has some similarities to Mojo::UserAgent: just use your request method (DELETE, GET, HEAD, POST, PUT) as the method name and pass the same arguments as you would do for `url_for`:

To build a post request with data, append the data hash at the end:

    my $res = app->subdispatch->post('route', foo => 'bar', {with => 'data'});

If you want to access the transaction object around the response, use the subdispatch helper with arguments like this:

    my $tx = app->subdispatch(GET  => 'route', foo => 'bar');
    my $tx = app->subdispatch(POST => 'route', foo => 'bar', {with => 'data'});

For some reasons, it seamed important to me to be able to set the base url of the resulting requests, so this is possible via

    plugin 'Subdispatch', base_url => '';

This is an early version and may change without warning. I'll use it to create static HTML pages from a Mojolicious blog, but if you find another good way to use it, please let me know!


This plugin lives in github: You're welcome to use github's issue tracker to report bugs or discuss the code:


Copyright Mirko Westermeier <>

Licensed under the same terms as Perl itself.