Dancer2-Plugin-WebService
view release on metacpan or search on metacpan
CREATE_SAMPLE_APPLICATION view on Meta::CPAN
get '/code/text_ref' => sub { reply sub { \'hello world' } }; # Code text reference
get '/code/list_ref' => sub { reply sub { [ 'a', 'b', 'c', 'd' ] } }; # Code list reference
get '/code/list_ref' => sub { reply sub { [ 'a', 'b', 'c', 'd' ] } }; # Code list reference
any['get','post','put'] => '/keys_selected' => sub { reply UserData('k1','k2') };
any['get','post'] => '/Protected' => sub { Error('ÏÏα'); reply UserData };
get '/Protected_text_ref' => sub { Error('ok'); reply \'hello world' }; # text reference
get '/project/commit' => sub { reply 'commited' };
# UniCode tests
any['get','post']=> '/unicode_test_mirror' => sub { reply UserData() };
any['get','post']=> '/unicode_test_session_set' => sub { reply SessionSet( UserData ) };
any['delete'] => '/unicode_test_session_del' => sub { reply SessionDel( UserData ) };
get '/unicode_test_session_get' => sub { reply { SessionGet( UserData ) } };
# Store persistent data
# SessionSet( { k1=>'v1' , k2=>'v2' } );
# SessionSet( k1=>'v1' , k2=>'v2' );
any['get','post','put'] => '/session_save' => sub {
my $arg = UserData();
my @arr = SessionSet( $arg );
reply { 'saved keys' => \@arr }
};
CREATE_SAMPLE_APPLICATION view on Meta::CPAN
Session idle timeout: 86400
Default format : json
Allowed hosts :
- "127.*"
- "172.20.20.*"
- "????:????:????:6d00:20c:29ff:*:ffa3"
- "10.*.?.*"
- "*"
Routes:
unicode_test_mirror : { Protected: false }
unicode_test_session_set : { Protected: false }
unicode_test_session_get : { Protected: false }
unicode_test_session_del : { Protected: false }
text : { Protected: false }
mirror : { Protected: false }
Protected : { Protected: true }
Protected_text_ref : { Protected: true }
list : { Protected: false }
list_ref : { Protected: false }
hash : { Protected: false }
code\/text : { Protected: false }
code\/list : { Protected: false }
code\/hash : { Protected: false }
CREATE_SAMPLE_APPLICATION view on Meta::CPAN
curl $url/session_save?token=$token -H "$H" -X POST -d '{ "Latin":"Hello world", "Îλληνικά":"Îειά ÏοÏ
κÏÏμε", "íêµ":"ìë
ì¸ê³" }'
curl $url/session_read?token=$token -H "$H" -X POST -d '[ "Latin", "Îλληνικά", "íêµ" ]'
curl $url/session_read?token=$token
curl $url/session_delete?token=$token -H "$H" -X DELETE -d '[ "Latin", "Îλληνικά", "íêµ" ]'
curl $url/logout?token=$token
curl $url/logout -H "$H" -X POST -d "{\"token\":\"$token\"}"
Unicode
Test if the unicode posted or replied data are handled successufully. Login is required
curl -X POST $url/unicode_test_mirror -H "$H" -d '{"Latin":"Hello world", "Îλληνικά":"Îειά ÏοÏ
κÏÏμε", "íêµ":"ìë
ì¸ê³"}'
curl -X POST "$url/unicode_test_mirror?from=xml&to=xml" -H "HXML" -d '<?xml version="1.0" encoding="UTF-8"?><root><Latin>hello world</Latin><Îλληνικά>Îειά ÏοÏ
κÏÏμε</Îλληνικά><íêµ>ìë
ì¸ê³</íêµ></root>'
curl -X POST $url/login -H "$H" -d '{"username":"joe", "password":"SomePassword"}'
export token=1767608823-2166cefaeba07576c7989e58-0
curl -X POST $url/unicode_test_session_set?token=$token -H "$H" -d '{ "Latin":"Hello world", "Îλληνικά":"Îειά ÏοÏ
κÏÏμε", "íêµ":"ìë
ì¸ê³" }'
curl -X GET $url/unicode_test_session_get?token=$token -H "$H" -d '[ "Latin", "Îλληνικά", "íêµ" ]'
curl -X DELETE $url/unicode_test_session_del?token=$token -H "$H" -d '[ "Latin", "Îλληνικά", "íêµ" ]'
curl -X POST $url/logout -H "$H" -d "{\"token\":\"$token\"}"
To start your application as Linux service
If you plan to use a reverse proxy change the listening IP (BIND) from 0.0.0.0 to 127.0.0.1
Locate the plackup with "find /usr/bin -name plackup -type f" e.g /usr/bin/site_perl/plackup
Edit/create the file /etc/systemd/system/TestService.service
[Unit]
Description=TestService rest API
4.8.7 2026-07-01
- Documentation changes
4.8.6 2026-05-01
- Clean up code
4.8.5 2026-04-01
- Bug fix at unicode session data
4.8.4 2026-04-01
- Bug fix at unicode session data
4.8.3 2025-12-31
- Changes at saved session data file names
4.8.2 2025-12-30
- Fix a group membership check bug
4.8.1 2025-11-03
( run in 1.853 second using v1.01-cache-2.11-cpan-39bf76dae61 )