Skip to content

Instantly share code, notes, and snippets.

@leobm
Created May 5, 2026 15:49
Show Gist options
  • Select an option

  • Save leobm/522cdbb58a2074303cd922919f29f1b8 to your computer and use it in GitHub Desktop.

Select an option

Save leobm/522cdbb58a2074303cd922919f29f1b8 to your computer and use it in GitHub Desktop.
Using HTTP::Server::PSGI and Plack, you can build something like this.
use strict;
use warnings;
use HTTP::Server::PSGI;
use Plack::Request;
use Plack::Response;
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $res = Plack::Response->new(200);
# Read query parameters (?user=name)
my $user = $req->parameters->{user} // 'Guest';
# Read headers
my $ua = $req->header('User-Agent');
# Set a cookie
$res->cookies->{session} = { value => 'abc123', path => '/' };
# Create the response
$res->content_type('text/html');
$res->body("<h1>Hello $user</h1><p>Your browser: $ua</p>");
return $res->finalize; # Generates the [status, headers, body] array
};
HTTP::Server::PSGI->new(port => 8080)->run($app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment