Skip to content

Instantly share code, notes, and snippets.

@xsawyerx
Last active August 29, 2015 14:08
Show Gist options
  • Save xsawyerx/cc94af2a25a60c9e38b5 to your computer and use it in GitHub Desktop.
Save xsawyerx/cc94af2a25a60c9e38b5 to your computer and use it in GitHub Desktop.
Example Dancer2 setup
# app.pl:
use MyApp::Web;
use MyApp::Web::API;
use Plack::Builder;
builder {
mount '/' => MyApp::Web->to_app;
mount '/api' => MyApp::Web::API->to_app;
};
# MyApp/Web.pm
package MyApp::Web {
use Dancer2;
set auto_page => 1;
get '/' => sub { template 'index' };
...
}
# MyApp/Web/API.pm
package MyApp::Web::API {
use Dancer2;
set serializer => 'JSON';
use MyApp::Web::API::Users;
use MyApp::Web::API::Projects;
...
}
# MyApp/Web/API/Users.pm
package MyApp::Web::API::Users {
use Dancer2 appname => 'MyApp::Web::API'; # bind to API
use Dancer2::Plugin::...;
prefix '/users' => sub {
get '/edit/:id' => sub {...};
get '/delete/:id' => sub {...};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment