sub base :Chained('/') :PathPart('myapp') :CaptureArgs(0) {} sub unauthenticated :Chained('base') :PathPart('authentication') :CaptureArgs(0) {} sub login :Chained('unauthenticated') :PathPart('login') :ActionClass('REST') {} sub login_POST { my $this = shift; my $c = shift; my $username = $c->request->data->{'username'} || ''; my $password = $c->request->data->{'password'} || ''; if($username eq '' || $password eq '') { $this->status_bad_request( $c, message => "Invalid username or password" ); $c->dispatch('end'); my $is_authenticated = $c->authenticate( { username => $username, password => $password } ); if(! $is_authenticated) { $this->status_bad_request( $c, message => "Invalid username or password" ); $c->dispatch('end'); } }