Request Data Handling in Mojolicious

This is just colorized HTML to illustrate the explanation in the wiki.

The Request

Three ways we can send arguments to a Mojolicious action -

  1. form fields (POST)
  2. query string (GET)
  3. and route captures (path parts of the url)

 <form method="post" 
 action="/form/reservation?arrival=friday&departure=sunday">
 <input name="room" value="42" type="text">
 <input name="surname" value="Adams" type="text">
 <input type="radio" name="breakfast" value="toast">toast
 <input type="radio" name="breakfast" value="eggs">eggs
 <input type="checkbox" name="season" value="summer">summer
 <input type="checkbox" name="season" value="winter">winter
 <input type="checkbox" name="season" value="autumn">autumn
 <input type="checkbox" name="season" value="spring">spring
 <input type="submit">
 </form>

Parameters

And here's how we can access them from the mojolicious controller, within code that looks like this:

post '/form/:test' => sub {
    my $self = shift; 
    . . .
    $self->render(...);
};

$self is a mojolicious controller. In each case, we call $obj->param for a list of names, $obj->param("arg") for the value (or list of values):

$self->param

params from route, post and get

PARAMVALUE
arrivalfriday
breakfasteggs
departuresunday
room42
seasonsummer
surnameAddams
testreservation

$self->req->param

params from post and get

PARAMVALUE
arrivalfriday
breakfasteggs
departuresunday
room42
seasonsummer
surnameAddams

$self->req->query_params

params from get

PARAMVALUE
arrivalfriday
departuresunday

$self->req->body_params

params from post

PARAMVALUE
breakfasteggs
room42
seasonsummer
surnameAddams