Last active
August 29, 2015 14:08
-
-
Save xsawyerx/cc94af2a25a60c9e38b5 to your computer and use it in GitHub Desktop.
Example Dancer2 setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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