mojolicious route->via->to vs post | get -> to

105 views Asked by At

I'm trying to understand mojolicious routing a little better.

Can someone explain the difference between using something like

$r->route('/register')->via('get')->to('auth#register')

as opposed to

$r->get('/register')->to('auth#register')

or are they exactly the same?

1

There are 1 answers

0
Sobrique On BEST ANSWER

Well spotted - they are the same.

get is a shorthand for route->via('get'). via is set up to restrict a route to particular methods (e.g. GET or POST or both). It might appear redundant, but consider how often you're likely to have a get() route in your Mojolicious app...