Skip to content

Instantly share code, notes, and snippets.

@dex4er
Created January 29, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dex4er/0522e1d3f09530eb8e8f08864ba6bfce to your computer and use it in GitHub Desktop.
Save dex4er/0522e1d3f09530eb8e8f08864ba6bfce to your computer and use it in GitHub Desktop.
ab -n 10000 -c 100 -T text/json -p ping.json http://127.0.0.1:5000/ping/
http -j post localhost:5000/ping/ pong=pong
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;
{"pong":"pong"}
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