1

I am trying to catch a route with regular expressions in Mojolicious Lite.

This is the route:

get qr!/messages/read/(.*).json! => sub {
    my $id = $1;
    my $c = shift;
    return $c->render(json => { $id => 1 });
};

It just returns page not found. I was wondering if I was missing a plugin or something has changed but I can't find anything.

I tried some variations, like adding a ^ before the first slash, or changing the character after qr but I couldn't make it work.

Thank you for your time.

Francesc Guasch
  • 317
  • 1
  • 9
  • I thought Mojo had regular expression after reading this: https://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Routes . It actually states this may be overkill but I thought they are available anyway. I guess it's not. – Francesc Guasch Oct 29 '18 at 07:03
  • That's building off the previous section which explains that regular expressions are often used for routing declarations; however, they aren't in Mojolicious, at least not directly. – Grinnz Oct 29 '18 at 22:03

1 Answers1

1

Mojolicious routes are not regular expressions, so I'm curious what led you to believe you could do this. It looks like you want a placeholder.

get '/messages/read/<:id>.json' => sub {
    my $c = shift;
    my $id = $c->param('id');
    return $c->render(json => { $id => 1 });
};
Grinnz
  • 9,093
  • 11
  • 18