Mojolicious::Plugin::Args - gives you back the request parameters as a simple %args hash, even if it's posted in json.
version 0.05
Route something like this:
package App; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; $self->plugin( 'Mojolicious::Plugin::Args' ); my $r = $self->routes; $r->any( '/example/test' )->to( 'example#test' ); }
Here's the controller:
package App::Example; use Mojo::Base 'Mojolicious::Controller'; sub test { my $self = shift; my %args = $self->args; $self->log->debug( 'args', $self->dumper( \%args ) ); $self->render( json => \%args ); }
Now send a POST to it (jQuery example):
$.ajax( { type: 'POST' ,url: '/example/test' ,contentType: 'application/json' ,dataType: 'json' ,data: JSON.stringify( { foo: 'bar' } ) } );
Inspect the response. Keen. Try a GET on the endpoint with ".json" typed (/example/test.json) and a json query string variable (?json=...). Same result.
/example/test.json
?json=...
$.ajax( { type: 'GET' ,url: '/example/test.json?json='+ JSON.stringify( { foo: 'bar' } ) } );
Also, try regular query string vars (e.g. ?foo=bar&baz=foo) and form-url-encoded POST stuff. Works the same. All-in-one: no more dealing with the stupid param helper.
?foo=bar&baz=foo
param
Please report any bugs or feature requests through the issue tracker at https://github.com/sharabash/mojolicious-plugin-args/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/sharabash/mojolicious-plugin-args
git clone git://github.com/sharabash/mojolicious-plugin-args.git
Nour Sharabash <amirite@cpan.org>
Nour Sharabash <nour.sharabash@gmail.com>
This software is copyright (c) 2014 by Nour Sharabash.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mojolicious::Plugin::Args, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Args
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Args
For more information on module installation, please visit the detailed CPAN module installation guide.