Created
January 29, 2018 11:53
-
-
Save dex4er/0522e1d3f09530eb8e8f08864ba6bfce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ab -n 10000 -c 100 -T text/json -p ping.json http://127.0.0.1:5000/ping/ |
This file contains hidden or 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
http -j post localhost:5000/ping/ pong=pong |
This file contains hidden or 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
use Mojolicious::Lite; | |
app->log->level('error'); | |
post '/ping' => sub { | |
my ($c) = @_; | |
my $json = $c->req->json; | |
my $pong = $json ? $json->{pong} : 'ping'; | |
$c->render(json => { pong => $pong }); | |
}; | |
app->start; |
This file contains hidden or 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
{"pong":"pong"} |
This file contains hidden or 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
use JSON::XS; | |
use Plack::App::URLMap; | |
use Plack::Request; | |
my $ping_app = sub { | |
my ($env) = @_; | |
my $req = Plack::Request->new($env); | |
my $content = $req->content; | |
my $json = decode_json $content if $content; | |
my $pong = $json ? $json->{pong} : 'ping'; | |
my $res = $req->new_response(200); | |
$res->content_type('text/json'); | |
$res->body(encode_json { pong => $pong }); | |
$res->finalize; | |
}; | |
my $urlmap = Plack::App::URLMap->new; | |
$urlmap->map('/ping' => $ping_app); | |
my $app = $urlmap->to_app; | |
$app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment