Hi Guys,

I'm using Mojolicious::Lite to build a simple API for a project. This is my 
code:

---------------------------------------------------------------------------------
app.pl
---------------------------------------------------------------------------------
use Mojolicious::Lite;

push @{ app->routes->namespaces }, 'MyAPI';

(get '/products/list')->to('Products#list');
(get '/products/add')->to('Products#add');
---------------------------------------------------------------------------------

---------------------------------------------------------------------------------
MyAPI::Products.pm
---------------------------------------------------------------------------------
package MyAPI::Products;

use Mojo::Base 'Mojolicious::Controller';

sub list {
  my $self = shift;
  $self->render(json => { hello => 'list' });
}

sub add {
  my $self = shift;
  $self->render(json => { hello => 'add' });
}

1;
---------------------------------------------------------------------------------

This works great and let me split my routers into several different files 
(keeping the simplicity of Mojolicious::Lite. My question is:

Instead of having to register all my routers in app.pl and map them into 
the .pm files, can't I use a wild card for that? Something like:

---------------------------------------------------------------------------------
(any '/products/*url')->to(cb => sub {
  my $c    = shift;
  my $url = $c->param('url');  
  print STDERR "####### $url\n";

  ??????????
});
---------------------------------------------------------------------------------

With this, I have on the $url vbl what I need for the routing, I just can't 
figure out how to translate that into the correct method on the controller 
(MyAPI::Products::list for example).

Thanks for the help.




-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to